How to change a new tip when turning the device?

I have a helloController, which is a UIViewController, if I rotate the device, I want it to change it to load the new nib "helloHorizontal.xib", how can I do this? thanks.

+6
objective-c iphone
source share
2 answers

You could be something like this (I don't have xcode, so this code may not be completely accurate)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)){ WhatYourNewViewClassISCAlled* newView = [[WhatYourNewViewClassISCAlled alloc] initWithNibName:@"NIBNAME" bundle:[NSBundle mainBundle]]; [self.navigationController pushViewController:newView animated:YES]; } 
+1
source share

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]; } } 
+1
source share

All Articles