2017-05-28 8 views
0

Ich bin mir nicht sicher, was los ist, ich habe darauf geachtet, den Delegaten auf sich selbst einzustellen, aber er wird immer noch nicht angerufen. Hier ist der Code:animationDidStop wird nicht aufgerufen?

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 

    //animate form 
    let flyRight = CABasicAnimation(keyPath: "position.x") 
    flyRight.fromValue = -view.bounds.size.width/2 
    flyRight.toValue = view.bounds.size.width/2 
    flyRight.duration = 0.5 
    heading.layer.add(flyRight, forKey: nil) 

    flyRight.isRemovedOnCompletion = false 
    flyRight.fillMode = kCAFillModeForwards 

    flyRight.delegate = self as? CAAnimationDelegate 
    flyRight.setValue("form", forKey: "name") 
    flyRight.setValue(username.layer, forKey: "layer") 
} 

Hier ist die animationDidStop:

func animationDidStop(_ anim: CAAnimation!, finished flag: Bool) { 
    let nameValue = anim.value(forKey: "name") as? String 
    if let name = nameValue { 
     if name == "form" { 
     let layer: CALayer = anim.value(forKey: "layer")! as! CALayer 
     layer.position.x = view.bounds.width/2 
     anim.setValue(nil, forKey: "layer") 
     } 
    } 
    } 
+0

In der Klassendeklaration Ich glaube, Sie fehlen: 'Klasse MyViewController: UIViewController, CAAnimationDelegate {// ...}' –

+0

Das war es, danke! – SwiftyJD

Antwort

0

In der Klassendeklaration Sie vermissen zu Protokoll entspricht

class MyViewController: UIViewController, CAAnimationDelegate { 
// ... 
}