Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS willRotateToInterfaceOrientation proper usage
    text
    copied!<p>I have a very simply UIViewController, and I'm trying to figure out how to use willRotateToInterfaceOrientation. my UIViewController has a very simple viewDidLoad method:</p> <pre><code>-(void)viewDidLoad { [super viewDidLoad]; theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)]; theBar.tintColor = [UIColor orangeColor]; UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"The Title"]; item.hidesBackButton = YES; [theBar pushNavigationItem:item animated:YES]; [item release]; [self.view addSubview:theBar]; } </code></pre> <p>So basically, I just have a UINavigationBar at the top of my controller. That's it. I implemented some methods for rotation, based on what I found online:</p> <pre><code>- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } -(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration { if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) { theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 640, 48)]; } } </code></pre> <p>So, I launch the app in portrait mode, and then I twist in in landscape mode. And basically, <code>theBar</code> still stays it's normal size, and doesn't get resized. I'm sure this is a silly question, but what is the proper way to use the rotation capability? I want to make it so that it also works if the app is launched in landscape mode. What is the best way to initialize my components when the UIViewController first launches, keeping in mind that I want support for both orientations, and also keeping in mind that I want to be able to change the size of everything based on orientation changes throughout the duration of the life of the UIViewController? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload