在iOS中实现PreceedOvershootInterpolator动画

在iOS中实现PreceedOvershootInterpolator动画,ios,animation,uislider,Ios,Animation,Uislider,我有一组需要设置动画的UISlider控件,从一个值到另一个值 动画的要求是,它需要匹配(尽可能接近)来自Android平台的动画效果。 PreventeOvershootInterpolator的文档提到: 一种插值器,其中更改从向后开始,然后向前抛出 并超出目标值,最终返回到最终值 价值观 带动画,取自 这就是我所拥有的结构。为了回答这个问题,重点将放在1 UISlider上 [UIView animateWithDuration:1.0 dela

我有一组需要设置动画的UISlider控件,从一个值到另一个值

动画的要求是,它需要匹配(尽可能接近)来自Android平台的动画效果。
PreventeOvershootInterpolator
的文档提到:

一种插值器,其中更改从向后开始,然后向前抛出 并超出目标值,最终返回到最终值 价值观

带动画,取自

这就是我所拥有的结构。为了回答这个问题,重点将放在1 UISlider上

[UIView animateWithDuration:1.0
                      delay:1.0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     [self.slider setValue:100 animated:YES];
                 } completion:^(BOOL finished) {
                     if (finished) {
                         //some other stuff
                     }
}];
我希望为
选项
参数(
UIViewAnimationOptionCurveEaseOut
在我的代码中,很遗憾与想要的效果不匹配)找到一个合适的值,该值将匹配
ExpectedOvershootInterpolator
效果。
我还意识到,使用
animateWithDuration
方法可能无法实现此效果,因此欢迎提供任何建议


我如何在iOS平台上实现
preventeOvershootInterpolator
效果?

如果您想通过UIView动画实现这一效果,那么最好的选择应该是关键帧动画

 UIView.animateKeyframes(withDuration: 0.8, delay: 0, options: [], animations: { 
    UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.25, animations: {
        // start animation update your values here
    })
    UIView.addKeyframe(withRelativeStartTime: 0.24, relativeDuration: 0.25, animations: { 
        // update the postion values here
    })

    // continue adding at least 2 more keyframes with relative start and change your values as you like them
}, completion: nil)
做这样的动画,甚至做得更好。你必须研究UIKit动力学

// self.view can be any view 
let animator = UIDynamicAnimator(referenceView: self.view)
它有很多有用的选择 您必须研究UIKit动态行为

  • 重力行为
  • UIFieldBehavior
  • 食指行为

在UIFieldBehavior中,您有许多有用的行为,您应该特别关注的行为将是电场也使用UISnapBehavior

如果您想通过UIView动画实现它,那么最好的选择应该是关键帧动画

 UIView.animateKeyframes(withDuration: 0.8, delay: 0, options: [], animations: { 
    UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.25, animations: {
        // start animation update your values here
    })
    UIView.addKeyframe(withRelativeStartTime: 0.24, relativeDuration: 0.25, animations: { 
        // update the postion values here
    })

    // continue adding at least 2 more keyframes with relative start and change your values as you like them
}, completion: nil)
做这样的动画,甚至做得更好。你必须研究UIKit动力学

// self.view can be any view 
let animator = UIDynamicAnimator(referenceView: self.view)
它有很多有用的选择 您必须研究UIKit动态行为

  • 重力行为
  • UIFieldBehavior
  • 食指行为

在UIFieldBehavior中,您有许多有用的行为,您应该特别关注的行为将是电场也使用UISnapBehavior

您可以通过首先制作常规动画来创建预期效果,该动画会降低值(需要设置动画),并在完成时添加动画​具有​持续时间:​延迟:​使用​春天​具有​阻尼:​最初的​春天​速度:​选项:​动画:​完成以超调效果设置滑块值的动画:)

像这样吗

[self.slider setValue:30 animated:NO];

[UIView animateWithDuration:1.0
                      delay:1.0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     [self.slider setValue:25 animated:YES];
               } completion:^(BOOL finished) {
                   if (finished) {
                       [UIView animateWithDuration:duration 
                                             delay:0 
                            usingSpringWithDamping:0.5
                             initialSpringVelocity:0.0f 
                                           options:0 
                                        animations:^{
                                            [self.slider setValue:80 animated:NO];
                                      } completion:nil];
                 }
}];

希望它能起作用:)

你可以先制作一个常规动画,减少值(需要设置动画),然后在完成时添加
动画,从而产生预期效果​具有​持续时间:​延迟:​使用​春天​具有​阻尼:​最初的​春天​速度:​选项:​动画:​完成
以超调效果设置滑块值的动画:)

像这样吗

[self.slider setValue:30 animated:NO];

[UIView animateWithDuration:1.0
                      delay:1.0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     [self.slider setValue:25 animated:YES];
               } completion:^(BOOL finished) {
                   if (finished) {
                       [UIView animateWithDuration:duration 
                                             delay:0 
                            usingSpringWithDamping:0.5
                             initialSpringVelocity:0.0f 
                                           options:0 
                                        animations:^{
                                            [self.slider setValue:80 animated:NO];
                                      } completion:nil];
                 }
}];
希望它能起作用:)