I\'ve been trying to run an animation that rotates my UIButton
360 degrees using this code:
UIView.animateWithDuration(3.0, animations: {
self.vin
As discussed here, you can also use a CAAnimation
. This code applies one full 360 rotation:
Swift 3
let fullRotation = CABasicAnimation(keyPath: "transform.rotation")
fullRotation.delegate = self
fullRotation.fromValue = NSNumber(floatLiteral: 0)
fullRotation.toValue = NSNumber(floatLiteral: Double(CGFloat.pi * 2))
fullRotation.duration = 0.5
fullRotation.repeatCount = 1
button.layer.add(fullRotation, forKey: "360")
You will need to import QuartzCore
:
import QuartzCore
And your ViewController
needs to conform to CAAnimationDelegate
:
class ViewController: UIViewController, CAAnimationDelegate {
}