gpt4 book ai didi

ios - animationDidStop 没有被调用?

转载 作者:行者123 更新时间:2023-11-28 06:19:04 27 4
gpt4 key购买 nike

我不确定出了什么问题,我确保将委托(delegate)设置为 self 但它仍然没有被调用。这是代码:

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

最佳答案

在你的类声明中你没有遵守协议(protocol)

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

关于ios - animationDidStop 没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44229758/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com