This is the right way, I think. I use it in my applications and it works great.
- the triggers on WILL rotate, and SHOULD NOT rotate (waiting for the rotation animation to begin)
- uses the Apple naming convention for landscape and portrait files (Default.png - Default-landscape.png if you want Apple to automatically download the landscape version)
- reloads a new NIB
- which resets self.view - this will automatically change the display
- and then it calls viewDidLoad (Apple will not call this for you if you manually reload the NIB)
(NB stackoverflow.com requires this suggestion here - there is an error in the formatting of the code)
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ) { [[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@-landscape", NSStringFromClass([self class])] owner:self options:nil]; [self viewDidLoad]; } else { [[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@", NSStringFromClass([self class])] owner:self options:nil]; [self viewDidLoad]; } }
Adam
source share