Reputation: 23
I have written a custom UIStoryboardSegue
which I'm using to transition between various UIViewControllers
. The animations work as desired, and much of the time the UIStoryboardSegue
displays as I'd expected both in the simulator and on the device.
However, sometimes after the segue completes, I can see the old UIViewController
flash for a fraction of a second after the UIStoryboardSegue
completes. The result disrupts the smooth transition I am expecting. Unfortunately, I can't discern any pattern for this behaviour.
I've included a barebones version of the approach I'm using to manage the segue below. Is there a more reliable method to insure smooth transitions? Am I doing something wrong? Again, much of the time the segue looks just the way I want.
- (void)perform
{
self.window = [[[UIApplication sharedApplication] delegate] window];
UIViewController *source = (UIViewController *) self.sourceViewController;
UIViewController *dest = (UIViewController *) self.destinationViewController;
[self.window insertSubview:dest.view.window belowSubview:source.view];
self.segueLayer = [CALayer layer];
// Create and add a number of other CALayers for displaying the segue,
// adding them to the base segueLayer
// Create and add CAAnimations for animating the CALayers
// (code omitted for the sake of space)
[self.window addSubview:dest.view];
[self.window.layer addSublayer:self.segueLayer];
[source.view removeFromSuperview];
}
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)isFinished
{
UIViewController *source = (UIViewController *) self.sourceViewController;
UIViewController *dest = (UIViewController *) self.destinationViewController;
if (isFinished)
{
// Remove and deallocate the CALayers previously created
[self.segueLayer removeFromSuperlayer];
self.segueLayer = nil;
self.window.rootViewController = dest;
}
}
Upvotes: 2
Views: 1133
Reputation:
So CAAnimations don't change the actual layer's values, but those of its associated presentationLayer
. Setting the fillMode
to kCAFillModeForwards
ensures that the presentationLayer
's values don't revert after the animation completes. However, if the animation's removedOnCompletion
property is set to YES
(which it is by default), the layer's appearance can also revert to its pre-animation state.
Since the animationDidStop:
callback likely gets invoked after any potential reversions, and because timings aren't exact, that would explain why you don't always see the reversion.
Upvotes: 2