I am developing iOS application in Swift and I want to rotate an image in 360 degrees with motion. Animation should be stop for 2 seconds once it completes each round.
I need 2 seconds delay after completion of every rotation. How can I set delay for it? I have done image rotation algorithm.
func rotate360Degrees(_ duration: CFTimeInterval = 1.0, completionDelegate: CAAnimationDelegate? = nil) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(M_PI * 2.0)
rotateAnimation.duration = duration
if let delegate: CAAnimationDelegate = completionDelegate {
rotateAnimation.delegate = delegate
}
rotateAnimation.repeatCount = Float.greatestFiniteMagnitude;
self.layer.add(rotateAnimation, forKey: nil)
}
For delay I have tried this:
let deadlineTime = DispatchTime.now() + .seconds(2)
DispatchQueue.main.asyncAfter(deadline: deadlineTime, execute: {
self.imgView.rotate360Degrees()
})
it is not working.