我正在做一个旧的项目,我想摆脱POP框架,我确信任何动画都可以用本机iOS框架完成。
这是旧代码:
POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
springAnimation.toValue = [NSValue valueWithCGRect:rect];
springAnimation.velocity = [NSValue valueWithCGRect:CGRectMake(springVelocity, springVelocity, 0, 0)];
springAnimation.springBounciness = springBounciness;
springAnimation.springSpeed = springSpeed;
[springAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
if (finished) {
// cool code here
}
}];
[self.selectedViewController.view pop_addAnimation:springAnimation forKey:@"springAnimation"];我试过的是:
[UIView animateWithDuration:1.0
delay:0
usingSpringWithDamping:springBounciness
initialSpringVelocity:springVelocity
options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.selectedViewController.view.frame = rect;
} completion:^(BOOL finished) {
// cool code here
}];但是我没有得到同样的结果,一些问题出现了:
springBounciness是否等同于usingSpringWithDamping?springSpeed在UIView动画中的等效性是什么?POPSpringAnimation的持续时间是什么?编辑:关于第三个问题,我在Github中找到了一个问题。
如果UIView不是要走的路,可以使用核心动画或任何其他iOS本地动画框架来完成吗?
发布于 2017-08-14 02:16:10
Pop参数值范围从0到20。但是usingSpringWithDamping没有这样的范围。显然,由于Pop是一个自定义库,它有自己的值范围,而UIView动画有自己的值。
从苹果文档来看,usingSpringWithDamping参数实际上是阻尼比,它指定:
若要平稳地减速动画而没有振荡,请使用1的值。使用接近于零的阻尼比来增加振荡。
1 .因此,如果您想要获得等效的弹性,您需要使用值小于1的值,我想您可以为springBounciness尝试以下公式。
float uiViewBounciness = (20.0 - springBounciness) / 20.0;
.. usingSpringWithDamping:uiViewBounciness ..2.对于springVelocity,Pop对所有动画帧都实现了相同的速度,而UIView动画只指定了初始速度,并且随着时间的推移这个速度会根据总持续时间和阻尼比而衰减。因此,为了尽可能接近动画,您可以执行以下操作:
float uiViewSpeed = springVelocity * 2.0;
.. initialSpringVelocity:uiViewSpeed ..3.至于持续时间,可以在animateWithDuration方法中实现与UIView方法相同的值。
最后,您需要对这些值进行实验,并将其与流行动画进行比较。我不认为您可以通过使用UIView动画获得完全相同的Pop动画,但它应该足够接近。
https://stackoverflow.com/questions/45526140
复制相似问题