I need to work with the animation and now I have such a function that rotates the view
func rotate360Degrees(uiView : UIView , duration: CFTimeInterval = 2.0, completionDelegate: AnyObject? = nil) { let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation") rotateAnimation.fromValue = 0.0 rotateAnimation.toValue = CGFloat(M_PI * 2) rotateAnimation.duration = duration if let delegate: CAAnimationDelegate = completionDelegate as! CAAnimationDelegate? { rotateAnimation.delegate = delegate } uiView.layer.add(rotateAnimation, forKey: nil) } But I am new and do not quite understand how you can use completionDelegate ?
I understand that we use delegate when we need to access methods of a particular class. Then you need to inherit from the class and make the delegate
But in this example, I do not quite understand for what purpose can I use this opportunity?
completionDelegatewhich I can pass, but I can not pass. If I do not pass it, then the method takes its default value to nil and of course theif let delegate: CAAnimationDelegatecheck fails. My question is that I understand thatcompletionDelegatemust pass a variable of typeCAAnimationDelegatethat the check has passed, but I don’t quite understand what will happen if I pass toCAAnimationDelegate? Why might you need to do this? - Aleksey Timoshchenko