Animate Rotating UIImageView

前端 未结 5 1687
予麋鹿
予麋鹿 2021-02-08 03:07

I want to rotate a UIImageView by roughly 10 degrees left/right but have a smooth animation, rather than a sudden turn which I see using:

play         


        
5条回答
  •  抹茶落季
    2021-02-08 03:29

    Converted for Swift 3/4:

    let animation = CABasicAnimation(keyPath: "transform.rotation")
    animation.fromValue = 0
    animation.toValue =  Double.pi * 2.0
    animation.duration = 2
    animation.repeatCount = .infinity
    animation.isRemovedOnCompletion = false
    
    imageView.layer.add(animation, forKey: "spin")
    

提交回复
热议问题