- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在做一个旧项目,想摆脱 POP framework我确信任何动画都可以使用原生 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
? UIView
动画中的 springSpeed
? POPSpringAnimation
的持续时间是多少? 编辑:关于第三个问题,我找到了一个 issue在 Github 上。
nếu như UIView
不是可行的方法,可以使用 Core Animation 或任何其他 iOS 原生动画框架来完成吗?
1 Câu trả lời
Pop 参数取值范围为 0-20。但是 usingSpringWithDamping 没有这样的范围。显然,由于 Pop 是一个自定义库,它有自己的取值范围,而 UIView 动画也有自己的取值范围。
从Apple的文档来看,usingSpringWithDamping参数其实就是damp ratio,它规定:
To smoothly decelerate the animation without oscillation, use a value of 1. Employ a damping ratio closer to zero to increase oscillation.
1.所以如果你想要等效的弹性,你需要使用任何小于 1 的值,我想你可以尝试下面的 springBounciness 公式。
float uiViewBounciness = (20.0 - springBounciness) / 20.0;
.. usingSpringWithDamping:uiViewBounciness ..
2.对于springVelocity,Pop对所有动画帧实现了相同的速度,而UIView动画只指定了INITIAL速度,这个速度根据总持续时间和阻尼比随时间衰减。因此,要获得尽可能接近的动画效果,您可以执行以下操作:
float uiViewSpeed = springVelocity * 2.0;
.. initialSpringVelocity:uiViewSpeed ..
3.至于持续时间,可以在UIView方法中实现与animateWithDuration相同的值。
最后,您需要试验这些值并将其与 Pop 动画进行比较。我不认为你可以通过使用 UIView animate 获得与 Pop 完全相同的动画,但它应该足够接近。
关于ios - 从 `POPSpringAnimation` 迁移到 Swift 4 中的原生 iOS 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45526140/
我在使用 POP 动画框架和 Swift 的 CGPoints 上遇到了一个奇怪的错误 我一直使用 Objective-C 和 Pop 来制作动画,但现在我正在尝试使用 Swift 做同样的事情,当我
我正在做一个旧项目,想摆脱 POP framework我确信任何动画都可以使用原生 iOS 框架完成。 这是旧代码: POPSpringAnimation *springAnimation = [PO
Tôi là một lập trình viên xuất sắc, rất giỏi!