I want to implement CABasicAnimation and have the UIViewController notified when the animation is completed. From this resource:
http://www.informit.com/articles/article.aspx?p=1168314&seqNum=2
I understood that I can specify the viewcontroller as a delegate for the animation and override animationDidStop
method within the viewcontroller. However when I convert the following line of code into Swift:
[animation setDelegate:self];
like so:
animation.delegate = self //there are no setDelegate method
XCode complains:
Cannot assign value of type 'SplashScreenViewController' to type 'CAAnimationDelegate?'
What am I doing wrong? Am I missing something?
You need to make sure your viewController conforms to the CAAnimationDelegate.
class SplashScreenViewController: UIViewController, CAAnimationDelegate {
// your code, viewDidLoad and what not
override func viewDidLoad() {
super.viewDidLoad()
let animation = CABasicAnimation()
animation.delegate = self
// setup your animation
}
// MARK: - CAAnimation Delegate Methods
func animationDidStart(_ anim: CAAnimation) {
}
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
}
// Add any other CAAnimationDelegate Methods you want
}
You can also conform to the delegate by use of an extension:
extension SplasScreenViewController: CAAnimationDelegate {
func animationDidStart(_ anim: CAAnimation) {
}
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With