首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Swift 4中从“Migrating动画”迁移到本机iOS框架

在Swift 4中从“Migrating动画”迁移到本机iOS框架
EN

Stack Overflow用户
提问于 2017-08-05 20:29:51
回答 1查看 527关注 0票数 6

我正在做一个旧的项目,我想摆脱POP框架,我确信任何动画都可以用本机iOS框架完成。

这是旧代码:

代码语言:javascript
复制
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"];

我试过的是:

代码语言:javascript
复制
[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. springSpeedUIView动画中的等效性是什么?
  3. POPSpringAnimation的持续时间是什么?

编辑:关于第三个问题,我在Github中找到了一个问题

如果UIView不是要走的路,可以使用核心动画或任何其他iOS本地动画框架来完成吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-14 02:16:10

Pop参数值范围从0到20。但是usingSpringWithDamping没有这样的范围。显然,由于Pop是一个自定义库,它有自己的值范围,而UIView动画有自己的值。

从苹果文档来看,usingSpringWithDamping参数实际上是阻尼比,它指定:

若要平稳地减速动画而没有振荡,请使用1的值。使用接近于零的阻尼比来增加振荡。

1 .因此,如果您想要获得等效的弹性,您需要使用值小于1的值,我想您可以为springBounciness尝试以下公式。

代码语言:javascript
复制
float uiViewBounciness = (20.0 - springBounciness) / 20.0;
.. usingSpringWithDamping:uiViewBounciness ..

2.对于springVelocity,Pop对所有动画帧都实现了相同的速度,而UIView动画只指定了初始速度,并且随着时间的推移这个速度会根据总持续时间和阻尼比而衰减。因此,为了尽可能接近动画,您可以执行以下操作:

代码语言:javascript
复制
float uiViewSpeed = springVelocity * 2.0; 
.. initialSpringVelocity:uiViewSpeed  ..

3.至于持续时间,可以在animateWithDuration方法中实现与UIView方法相同的值。

最后,您需要对这些值进行实验,并将其与流行动画进行比较。我不认为您可以通过使用UIView动画获得完全相同的Pop动画,但它应该足够接近。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45526140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档