Ios UINavigationBar在iPhone旋转后消失
我有一个应用程序可以在didFinishLaunchingWithOptions方法中设置UINavigationController,如下所示:Ios UINavigationBar在iPhone旋转后消失,ios,uinavigationcontroller,rotation,uinavigationbar,landscape,Ios,Uinavigationcontroller,Rotation,Uinavigationbar,Landscape,我有一个应用程序可以在didFinishLaunchingWithOptions方法中设置UINavigationController,如下所示: main_iPhone *mainiPhone = [[main_iPhone alloc] initWithNibName:@"main_iPhone" bundle:nil]; mainiPhone.navigationItem.title = @"TitleHere"; UIBarButtonItem *botaoSobre = [[UIB
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;
- (void)willAnimateRotationToInterfaceOrientation:
运行应用程序时,导航栏仅在纵向模式下正确显示。但是,当我旋转设备以横向移动时,导航栏消失。当我旋转回到纵向时,导航栏也不会回来
PS:My mainiPhone.xib文件有两个视图,一个在纵向模式,一个在横向模式。我在主iPhone内切换视图。m如下所示:
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;
- (void)willAnimateRotationToInterfaceOrientation:
UIInterfaceOrientation界面定向持续时间:
NSTimeInterval持续时间{
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);
}
}
另外,我的shouldAutorotateToInterfaceOrientation方法只返回YES
我做错了什么?
提前非常感谢 如果我添加UINavigationController*navC=[self-navigationController];作为WillAnimateRotationInterfaceOrientation方法的第一行,它返回nil。不知何故,当设备旋转时,我在didFinishLaunchingWithOptions方法中创建的导航控制器丢失了,但我不知道为什么。