UIViewPropertyAnimator different behaviour on iOS10 and iOS11 reversing an animation. Bug on `isReversed` and `fractionComplete` properties?

后端 未结 3 1839
你的背包
你的背包 2021-02-06 00:16

THE PROBLEM
Running the same code on iOS10 and iOS11 my UIViewPropertyAnimator has a different behaviour just after changing of his .isReversed

3条回答
  •  我在风中等你
    2021-02-06 00:30

    1. On iOS 11, fractionComplete will be reversed (that is, 1 - originalFractionComplete) after you reverse animation by animator.isReversed = true.

    2. Spring animation that have less than 0.1s duration will complete instantly.

    So you may originally want the reversed animation runs 90% of the entire animation duration, but on iOS 11, the reversed animation actually runs 10% duration because isReversed changed, and that 10% duration is less than 0.1s, so the animation will be completed instantly and looks like no animation happened.

    How to fix?

    For iOS 10 backward compatibility, copy the fractionComplete value before you reverse animation and use it for continueAnimation.

    e.g.

    let fraction = animator.fractionComplete
    animator.isReversed = true
    animator.continueAnimation(...*fraction*...)
    

提交回复
热议问题