animate rotation UIImageView in swift

后端 未结 10 2280
抹茶落季
抹茶落季 2021-02-06 23:11

I\'m trying to animate a rotation of 180 degrees of a UIImageView in Swift

    UIView.animateWithDuration(1.0, animations: { () -> Void in
              


        
10条回答
  •  南方客
    南方客 (楼主)
    2021-02-06 23:23

    Updated swift 4.0 version:

        let rotation: CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
        rotation.toValue = Double.pi * 2
        rotation.duration = 0.25 // or however long you want ...
        rotation.isCumulative = true
        rotation.repeatCount = Float.greatestFiniteMagnitude
        yourView.layer.add(rotation, forKey: "rotationAnimation")
    

提交回复
热议问题