Question

I'd like to know how Apple had implemented its great custom interactive transition system and I think it should be interesting to create something similar just as experiment.

This is my thoughts on this "problem".

The developer creates the animation that he needs within UIView animationWithDuration and this animation is called thanks to animatedTransition:

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{

    ... Perform configurations, get data about from/to controllers.

    [UIView animateWithDuration:self.presentationDuration 
                          delay:0.0f 
         usingSpringWithDamping:0.4f 
          initialSpringVelocity:6.0f 
                        options:UIViewAnimationOptionCurveEaseIn animations:^{

                             toViewController.view.center = aValueFromPreviousConfig;

                  } completion:^(BOOL finished) {

                             [transitionContext completeTransition:YES];
    }];
}

My curiosity starts here. How, starting from this definition, Apple can perform an interactive transition?

How they take the animation that is defined in this function and convert it in an interactive one?

I suppose Apple uses something of its new UIView Key-Frame Animations API but I can't find a way to match the code written within the animatedTransition function (that could be whatever-code) and am arbitrary percentage status of completion of the animation.

Have you some thoughts about how they implemented it?

(please... no runts like "Could you just use this API without knowing how it works?").

Was it helpful?

Solution

I found that probably the "trick" is just starting the animation and then managing layer speed and timeoffset with this code:

CALayer *layer = self.theView.layer;
CFTimeInterval pausedTime = 2.0 * v;
layer.speed = 0.0;
layer.timeOffset = pausedTime;

I'm doing some tests and it works quite well :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top