I have an app that sets the UINavigationController in the didFinishLaunchingWithOptions method like this:
main_iPhone *mainiPhone = [[main_iPhone alloc] initWithNibName:@"main_iPhone" bundle:nil];
mainiPhone.navigationItem.title = @"TitleHere";
UIBarButtonItem *botaoSobre = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:mainiPhone action:@selector(goToAboutView)];
mainiPhone.navigationItem.rightBarButtonItem = botaoSobre;
navController = [[UINavigationController alloc] initWithRootViewController:mainiPhone];
navController.navigationBar.tintColor = [UIColor orangeColor];
navController.navigationBar.translucent = NO;
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
When I run the application, the navigation bar appears correctly only in portrait mode. However, when I rotate the device to landscape the NavigationBar disappears. When I rotate back to portrait way I also don`t get the NavigationBar back.
PS: My mainiPhone.xib file has 2 views (one in portrait mode and one in 开发者_开发问答landscape mode). I switch the views inside the mainiPhone.m like this:
- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
self.view = self.portrait;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);
} else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
self.view = self.portrait;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0);
}
}
Also, my shouldAutorotateToInterfaceOrientation method just returns YES.
What am I doing wrong? Thank you very much in advance!
精彩评论