Interactive transition similar to scroll view

658 views Asked by At

I have implemented an interactive transition between two view controllers, using gesture recognizer and UIPercentDrivenInteractiveTransition. I am doing custom swipe transition.

I would like to improve 2 things in order to have similar to scrollview animation:

  1. Responsiveness. When you pan super fast and short, the next vc is not even showed, plus a bug comes in (animationEnded is not called, but this is another story) Is there a way to preload the next view controller, have it as a child view controller may be? It seems like I am doing too much work in viewDidLoad.

  2. In my implementation when the gesture recognizer ends, I call finishInteractiveTransition. This works ok, but if you start a new pan gesture before this transition is completed the UI just jumps instead of smoothly scrolling. So may be I should call finishInteractiveTransition after a delay, and calling manually updateInteractiveTransition in the mean time?

May be I can use another API sets to have interactive animation (but scrollview is not an option)?

Just FYI: Here is my view hierarchy during interactive swipe, my gesture is attached to the navigation view:

during interactive swipe

1

There are 1 answers

4
rounak On

Try subclassing UIPercentDrivenInteractiveTransition and implement these methods. This should help smoothen out the jerks:

- (void)startInteractiveTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    [super startInteractiveTransition:transitionContext];
    self.layer = transitionContext.containerView.layer;
}

- (void)finishInteractiveTransition
{
    [super finishInteractiveTransition];
    self.layer.speed = 1;
    self.layer.beginTime = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil] - self.layer.timeOffset;
}

- (void)cancelInteractiveTransition
{
    [super cancelInteractiveTransition];
    self.layer.speed = -1;
    self.layer.beginTime = CACurrentMediaTime();
}