sách gpt4 ai đã đi

ios - 从 `POPSpringAnimation` 迁移到 Swift 4 中的原生 iOS 框架

In lại 作者:塔克拉玛干 更新时间:2023-11-02 08:11:35 27 4
mua khóa gpt4 Nike

我正在做一个旧项目,想摆脱 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
}];

但我没有得到相同的结果,并且出现了一些问题:

  1. 在 pop 中 springBounciness 是否等同于 usingSpringWithDamping ?
  2. 什么相当于 UIView 动画中的 springSpeed?
  3. 持续时间如何,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/

27 4 0
Bài viết được đề xuất: ios - 应用程序因准则 3.2 被拒绝 - 业务,下一步该怎么做?
Bài viết được đề xuất: java - 通过传递参数和结果从 Java 调用 Python 代码
Bài viết được đề xuất: Java HashSet 包含对象
Bài viết được đề xuất: ios - 同时向两个 Firebase 项目报告
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com