2017-02-05 5 views
0

CABasicAnimation을 구현하고 애니메이션이 완료되면 UIViewController에 알리고 싶습니다. 이 자원에서 : 애니메이션 위젯이 Swift 3.0으로 변환되지 않음

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

은 내가 애니메이션의 대리자로의 ViewController를 지정하고의 ViewController에서 animationDidStop 메소드를 오버라이드 (override) 할 수 있음을 이해했다. 그러나 나는 스위프트에 다음 코드 줄을 변환 할 때 :

[animation setDelegate:self]; 

과 같이 :

animation.delegate이 = 자기 // 더 setDelegate 방법이없는

엑스 코드는 불평 :

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

    } 
} 
관련 문제