Rotate a view for 360 degrees indefinitely in Swift?

后端 未结 10 1192
闹比i
闹比i 2020-12-05 13:06

I want to rotate an image view for 360 degrees indefinitely.

UIView.animate(withDuration: 2, delay: 0, options: [.repeat], animations: {
    self.view.transf         


        
10条回答
  •  -上瘾入骨i
    2020-12-05 13:39

    This one work for me in Swift 2.2:

    let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
    rotationAnimation.fromValue = 0.0
    rotationAnimation.toValue = 360 * CGFloat(M_PI/180)
    let innerAnimationDuration : CGFloat = 1.0
    rotationAnimation.duration = Double(innerAnimationDuration)
    rotationAnimation.repeatCount = HUGE
    self.imageView.addAnimation(rotationAnimation, forKey: "rotateInner")
    

提交回复
热议问题