2017-05-28 3 views
0

何が間違っているのか分かりません。私はデリゲートを自分に設定するようにしましたが、まだ呼び出されていません。ここでは、コードは次のようになります。ここではanimationDidStopが呼び出されていませんか?

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") 
} 

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

に準拠不足している私は、あなたが不足していると思います: 'class MyViewController:UIViewController、CAAnimationDelegate {// ...}' –

+0

それはありがとう! – SwiftyJD

答えて

0

あなたのクラス宣言ではプロトコル

class MyViewController: UIViewController, CAAnimationDelegate { 
// ... 
} 
関連する問題