I\'m trying to animate a rotation of 180 degrees of a UIImageView
in Swift
UIView.animateWithDuration(1.0, animations: { () -> Void in
First of all, if you want to rotate 180 degrees, that has to translate to radians. 180 degrees in radians is pi
. 360 degrees would be 2 * pi
. 180 * pi
would make your animation spin around 90 times in one second and end up with the original orientation.
Secondly, I'm not sure why your code isn't working, but I know that the code below does work:
let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotationAnimation.fromValue = 0.0
rotationAnimation.toValue = M_PI
rotationAnimation.duration = 1.0
self.arrowImageView.layer.addAnimation(rotationAnimation, forKey: nil)