使用 POPDecayAnimation 时动画不工作
Animation not working when use POPDecayAnimation
我为改变视图制作了下拉动画。当我使用 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
属性,结束状态是根据起始位置、速度和减速度来确定的。
您还需要为图层位置而不是视图框架设置动画。所以像这样的东西应该有用...
var animation = POPDecayAnimation()
animation.property = POPAnimatableProperty.propertyWithName(kPOPLayerPosition) as POPAnimatableProperty
from!.view.layer.pop_addAnimation(animation, forKey: "dropDown")
我为改变视图制作了下拉动画。当我使用 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
属性,结束状态是根据起始位置、速度和减速度来确定的。
您还需要为图层位置而不是视图框架设置动画。所以像这样的东西应该有用...
var animation = POPDecayAnimation()
animation.property = POPAnimatableProperty.propertyWithName(kPOPLayerPosition) as POPAnimatableProperty
from!.view.layer.pop_addAnimation(animation, forKey: "dropDown")