I\'ve been trying to run an animation that rotates my UIButton
360 degrees using this code:
UIView.animateWithDuration(3.0, animations: {
self.vin
Swift 5. Try this, it worked for me
UIView.animate(withDuration: 3) {
self.yourButton.transform = CGAffineTransform(rotationAngle: .pi)
self.yourButton.transform = CGAffineTransform(rotationAngle: .pi * 2)
}
You can use a trick: start rotating with 180 degrees first and then rotate with 360 degrees. Use 2 animations with delay. Try this.
Swift 2
UIView.animateWithDuration(0.5) { () -> Void in
button.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}
UIView.animateWithDuration(0.5, delay: 0.45, options: UIViewAnimationOptions.CurveEaseIn, animations: { () -> Void in
button.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 2))
}, completion: nil)
Swift 3, 4, 5
UIView.animate(withDuration: 0.5) { () -> Void in
self.settingsButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
}
UIView.animate(withDuration: 0.5, delay: 0.45, options: UIViewAnimationOptions.curveEaseIn, animations: { () -> Void in
self.settingsButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi * 2.0)
}, completion: nil)
Hope this helps