Ios 动画代理未转换为Swift 3.0

Ios 动画代理未转换为Swift 3.0,ios,swift,delegates,core-animation,caanimation,Ios,Swift,Delegates,Core Animation,Caanimation,我想实现CABasicAnimation,并在动画完成时通知UIViewController。从该资源: 我知道我可以将viewcontroller指定为动画的代理,并覆盖viewcontroller中的animationDidStop方法。但是,当我将以下代码行转换为Swift时: [animation setDelegate:self]; 像这样: animation.delegate=self//没有setDelegate方法 XCode投诉: Cannot assign value

我想实现CABasicAnimation,并在动画完成时通知UIViewController。从该资源:

我知道我可以将viewcontroller指定为动画的代理,并覆盖viewcontroller中的
animationDidStop
方法。但是,当我将以下代码行转换为Swift时:

[animation setDelegate:self];
像这样:

animation.delegate=self//没有setDelegate方法

XCode投诉:

Cannot assign value of type 'SplashScreenViewController' to type 'CAAnimationDelegate?'

我做错了什么?我遗漏了什么吗?

您需要确保viewController符合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

}
您还可以通过使用扩展来符合委托:

extension SplasScreenViewController: CAAnimationDelegate {
    func animationDidStart(_ anim: CAAnimation) {

    }

    func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {

    }
}