gpt4 book ai didi

ios - 使用 POPDecayAnimation 时动画不工作

转载 作者:行者123 更新时间:2023-11-29 02:22:14 25 4
gpt4 key购买 nike

我为改变 View 制作下拉动画。当我使用 POPSpringAnimation 时,一切正常。但是当我将 POPSpringAnimation 更改为 POPDecayAnimation 时,什么也没有发生,在调试输出中我看到了这条消息:

ignoring to value on decay animation <POPDecayAnimation:0x7f9f2b5c8700; from = null; to = null; deceleration = 0.998000>

代码:

func switchViewController(from: UIViewController?, toViewController to: UIViewController?, animated: Bool) {

if animated {
to!.view.frame = self.view.frame
// Not working when call trulySwitchViewController
self.addChildViewController(to!)
self.view.insertSubview(to!.view, belowSubview: from!.view)
to!.didMoveToParentViewController(self)
// Calculate new x coord
var frame = from!.view.frame
frame.origin.y += frame.size.height

// POPDecayAnimation not working here
var animation = POPDecayAnimation()
animation.property = POPAnimatableProperty.propertyWithName(kPOPViewFrame) as POPAnimatableProperty
animation.toValue = NSValue(CGRect:frame)
animation.completionBlock = {
(_, _) in
self.trulySwitchViewController(from, toViewController: nil)
}

from!.view.pop_addAnimation(animation, forKey: "dropDown")
} else {
to?.view.frame = self.view.frame
self.trulySwitchViewController(from, toViewController: to)
}
}

最佳答案

对于衰减动画,您需要设置 velocity 属性,然后根据 deceleration 属性衰减到零。因此,不需要 to 属性,结束状态是根据起始位置、速度和减速度确定的。

您还需要为图层位置而不是 View 框架设置动画。所以像这样的东西应该工作......

var animation = POPDecayAnimation()
animation.property = POPAnimatableProperty.propertyWithName(kPOPLayerPosition) as POPAnimatableProperty

from!.view.layer.pop_addAnimation(animation, forKey: "dropDown")

关于ios - 使用 POPDecayAnimation 时动画不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28010510/

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