Since iOS8, there is the very convenient viewWillTransitionToSize method to handle interface orientation changes. I use this the following way in my app (for the sake of simplicity, I only use a single UIView, elementView, I want to resize in the example):
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
// Define the new screen size we are about to transition to
windowSize = size;
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context){
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
// Animate UI element to new dimensions
[self setUpUIElements];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context){
// Housekeeping after animation (just so there is something here)
randomBool = YES;
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
-(void) setUpUIElements {
elementView.frame = CGRectMake(0.0f,
0.0f,
windowSize.size.width,
windowSize.size.height);
}
This method handles orientation changes beautifully, animating the resize method alongside the actual rotation; couldn't be any simpler. I, however, would like to support iOS 7 alongside iOS8 and iOS9, and this method is not available there. So, my question is:
How could I get the same smoothly animated resizing result with legacy, iOS7 code?
I was experimenting with methods like willRotateToInterfaceOrientation but was having trouble determining the exact dimensions of the new interface and how to animate my resizing methods alongside the device rotation. I need help from someone who is more familiar with legacy code.
Since there was no answer, I was forced to dig through old documentations and spend a few days trying out various solutions. Long story short: the below method do the job just done (I hope it will help people who want to support legacy devices):