2016-03-29 14 views
0

私はこのような私のイメージ図で変換したい:私は風景モードを使用複数の変換のUIView

enter image description here

は、私はパンダが左から垂直中心に開始したい、それが再び360を回転させますし、再び大きくなり、右に向かって中心に向かいます。

enter image description here

私はこのように試してみました:

import UIKit 

class ViewController: UIViewController { 

    @IBOutlet var imageView: UIImageView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     let scale = CGAffineTransformMakeScale(3.0, 3.0) 
     let rotate = CGAffineTransformMakeRotation(180*CGFloat(M_PI)/180) 
     let translate = CGAffineTransformMakeTranslation(UIScreen.mainScreen().bounds.width - 100, 0) 
     UIView.animateWithDuration(3.0, delay: 0, options: [.Repeat, .Autoreverse, .CurveEaseInOut], animations: {() -> Void in 
      let mixTransform = CGAffineTransformConcat(scale, translate) 
      self.imageView.transform = mixTransform 
      self.view.layoutIfNeeded() 
      }, completion: nil) 
     UIView.animateWithDuration(1.0, delay: 0, options: [.Repeat, .Autoreverse, .CurveEaseInOut], animations: {() -> Void in 
      self.imageView.transform = rotate 
      }, completion: nil) 
    } 
} 

しかし、それはうまく動作しません。

enter image description here

答えて

0

あなたの変換は、明らかにあなたの要件に合わせてはいけません。

画像を比例的に拡大するには、XとYに異なる縮尺を設定するのはなぜですか?

また、画像をX軸に沿って移動させたい場合は、変換でY軸の位置を調整するのはなぜですか?変換を修正するだけで、すぐに使用できます。特に

:ここ

let scale = CGAffineTransformMakeScale(3.0, 3.0) 
... 
let translate = CGAffineTransformMakeTranslation(UIScreen.mainScreen().bounds.width - 400, 0) 
+0

私のように変換したときに、私は、翻訳し、回転させるといくつかの問題がありますあなたは言った、パンダは、底の中央に行く – Khuong

+0

私は回転トランスを削除する場合フォームの場合、それはまっすぐ進む – Khuong

+0

それはUIViewのアンカーポイントで何かでなければなりません、それを(0.5、0.5)に設定しようとしましたか? – s1ddok

0

が私の答えです:

import UIKit 
import QuartzCore 

class ViewController: UIViewController { 

    @IBOutlet var imageView: UIImageView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let kRotationAnimationKey = "com.myapplication.rotationanimationkey" 

     func rotateView(view: UIView, duration: Double = 1) { 
      if view.layer.animationForKey(kRotationAnimationKey) == nil { 
       let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation") 

       rotationAnimation.fromValue = 0.0 
       rotationAnimation.toValue = Float(M_PI * 2.0) 
       rotationAnimation.duration = duration 
       rotationAnimation.repeatCount = Float.infinity 

       view.layer.addAnimation(rotationAnimation, forKey: kRotationAnimationKey) 
      } 
     } 

     func stopRotatingView(view: UIView) { 
      if view.layer.animationForKey(kRotationAnimationKey) != nil { 
       view.layer.removeAnimationForKey(kRotationAnimationKey) 
      } 
     } 

     var transform = CGAffineTransformMakeTranslation(UIScreen.mainScreen().bounds.width - 200, 0) 
     transform = CGAffineTransformScale(transform, 3.0, 3.0) 
     UIView.animateWithDuration(1.0, delay: 0, options: [.Repeat, .Autoreverse, .CurveEaseInOut], animations: {() -> Void in 
      self.imageView.transform = transform 
      rotateView(self.imageView) 
      self.view.layoutIfNeeded() 
      }) { (_) -> Void in 
       stopRotatingView(self.imageView) 
     } 
    } 

} 

結果:

enter image description here

関連する問題