2017-02-05 7 views
0

CABasicAnimationを実装し、アニメーションが完了したときにUIViewControllerに通知する必要があります。このリソースから:アニメーション代理人がSwift 3.0に変換しない

http://www.informit.com/articles/article.aspx?p=1168314&seqNum=2

私はアニメーションのためのデリゲートとしてのViewControllerを指定してのViewController内animationDidStopメソッドをオーバーライドすることができると理解しました。そのよう

[animation setDelegate:self]; 

::私はスウィフトに次のコード行を変換する場合しかしながら、

animation.delegate =自己//何setDelegate方法がない

Xcodeは文句:

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

私は何が間違っていますか?何か不足していますか?

答えて

4

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) { 

    } 
} 
関連する問題