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

后端 未结 3 1841
你的背包
你的背包 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:43

    I have tried many solutions, but no one didn't work for me. I wrote my solution and everything is fine now. My solution:

    1. take an image of the screen and show it

    2. finish animation

    3. start new animation for old state

    4. pause the animation and set progress (1 - original progress)

    5. remove screen image and continue animation

      switch pan.state {
      ...
      case .ended, .cancelled, .failed:
          let velocity = pan.velocity(in: view)
          let reversed: Bool
      
          if abs(velocity.y) < 200 {
              reversed = progress < 0.5
          } else {
              switch state {
              case .shown:
                  reversed = velocity.y < 0
              case .minimized:
                  reversed = velocity.y > 0
              }
          }
      
          if reversed {
              let overlayView = UIScreen.main.snapshotView(afterScreenUpdates: false)
              view.addSubview(overlayView)
              animator?.stopAnimation(false)
              animator?.finishAnimation(at: .end)
              startAnimation(state: state.opposite)
              animator?.pauseAnimation()
              animator?.fractionComplete = 1 - progress
              overlayView.removeFromSuperview()
              animator?.continueAnimation(withTimingParameters: nil, durationFactor: 0.5)
          } else {
              animator?.continueAnimation(withTimingParameters: nil, durationFactor: 0)
          }
      

    And the animation curve option must be linear.

        animator = UIViewPropertyAnimator(duration: 0.3, curve: .linear) {
            startAnimation()
        }
    

提交回复
热议问题