2016-03-29 10 views
0

: Ben manzara modunu kullanmakÇoklu dönüşümleri UIView Bu gibi benim görüntü görünümünü dönüştürmek istediğiniz

enter image description here

, panda, soldan dikey merkezinde başlayacak sonra tekrar 360 dönecektir istiyoruz ve yine daha büyük ve daha büyük hale gelir ve merkeze doğru sağa doğru gider.

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) 
    } 
} 

Ama iyi çalışmıyor:

enter image description here

böyle çalıştık.

enter image description here

cevap

0

Sizin dönüşümler besbelli ihtiyaçlarınızı uymaz.

Görüntünün orantılı olarak ölçeklenmesini istiyorsanız, neden X ve Y için farklı ölçekler ayarladınız?

Yine de, görüntünün X ekseni boyunca hareket etmesini istiyorsanız, neden Y konumunu dönüşümde ayarlıyorsunuz? Sadece dönüşümünüzü düzeltin ve gitmeye hazırsınız. Özellikle

: Burada

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

ben tercüme ile bazı sorunlar var ve olarak tercüme ayarladığınızda, döndürme dedin ki, panda, – Khuong

+0

'un ortasına git. form, ileriye doğru gidiyor – Khuong

+0

UIView çapa noktası olan bir şey olmalı, (0.5, 0.5) 'e ayarlamaya çalıştınız mı? – s1ddok

0

cevabım ise:

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) 
     } 
    } 

} 

Sonuç:

enter image description here

İlgili konular