2017-02-05 2 views
0

Ich möchte CABasicAnimation implementieren und den UIViewController benachrichtigt werden, wenn die Animation abgeschlossen ist. Von dieser Ressource:Animation Delegate nicht zu Swift 3.0 konvertieren

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

ich verstanden, dass ich die Viewcontroller als Delegierter für die Animation angeben und animationDidStop Methode innerhalb des Viewcontroller außer Kraft setzen. Allerdings, wenn ich wandeln die folgende Codezeile in Swift:

[animation setDelegate:self]; 

wie so:

animation.delegate = Selbst // gibt es keine setDelegate Methode

XCode klagt:

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

Was mache ich falsch? Fehle ich etwas?

Antwort

4

Sie müssen sicherstellen, dass Ihr ViewController dem CAAnimationDelegate entspricht.

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 

} 

Sie auch zu den Delegierten durch die Verwendung einer Erweiterung anpassen können:

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

    } 

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

    } 
}