UIPercentDrivenInteractiveTransition doesn't get to animation's completion on fast gesture

前端 未结 3 1455
礼貌的吻别
礼貌的吻别 2021-02-04 19:05

I have created an interactive transition. My func animateTransition(transitionContext: UIViewControllerContextTransitioning) is quite normal, I get the container

3条回答
  •  野的像风
    2021-02-04 19:34

    Have the same issue, tried to use serialQueue.suspend()/resume(), does not work.

    This issue is because when pan gesture is too fast, end state is earlier than animateTransition starts, then context.completeTransition can not get run, the whole animation is messed up.

    My solution is forcing to run context.completeTransition when this situation happened.

    For example, I have two classes:

    class SwipeInteractor: UIPercentDrivenInteractiveTransition {
        var interactionInProgress = false
    
        ...
    }
    
    class AnimationController: UIViewControllerAnimatedTransitioning {
        func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
            if !swipeInteractor.interactionInProgress {
                DispatchQueue.main.asyncAfter(deadline: .now()+transitionDuration) {
                    if context.transitionWasCancelled {
                        toView?.removeFromSuperview()
                    } else {
                        fromView?.removeFromSuperview()
                    }
                    context.completeTransition(!context.transitionWasCancelled)
                }
            }
    
            ...
        }
    
        ...
    }
    

    interactionInProgress is set to true when gesture began, set to false when gesture ends.

提交回复
热议问题