In iOS (version 5 is fine), I have a custom animation to flip and zoom an image transitioning from one UIViewController to another using:
TCFlipZoomSubviewSegue segue=[[TCFlipZoomSubviewSegue alloc] initWithIdentifier:@"SegueToMenuTable" source:self.iViewController destination:self.mViewController];
[segue perform];
and in the perform method I have:
[UIView animateWithDuration:3.75f
delay:0.0f
options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
self.subviewTransformView.layer.transform=transform;
} completion:^(BOOL finished) {
[destination.parentViewController.view bringSubviewToFront:destination.view];
}
It all works fine, but all sorts of problems occur (layout is messed up) if I rotate the device during the animation. What I want is for the animation to complete before the orientation event occurs – which is the standard behaviour in iPhones – eg try rotating the MAIL app immediately after clicking INBOX – it completes the slide transition then rotates. Same with the Stocks app etc. And that’s what happens if I use a standard Push animation etc. But I have my own animation to do.
So how do they do that?
How do I prevent (ie delay, or block) the orientation change until my animation finishes? I can easily stop the change by saying NO in shouldAutorotateToInterfaceOrientation: when I’m animating but then i need it to do the orientation after. I could call attemptRotationToDeviceOrientation but surely there must be a better way – The segue itself should be able to complete without being interrupted.
I think the way you mentioned is probably the way you have to do it — that is, return NO to shouldAutorotateToInterfaceOrientation:, and then call attemptRotationToDeviceOrientation when your animation is done. You would probably need some sort of flag that is set if the user tries to rotate while the animation is in progress, so you would know whether you should call attemptRotationToDeviceOrientation when the animation finishes.