iPhone 旋转后 UINavigationBar 消失
我有一个应用程序在 didFinishLaunchingWithOptions 方法中设置 UINavigationController,如下所示:
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;
当我运行该应用程序时,导航栏仅在纵向模式下正确显示。但是,当我旋转设备以横向显示时,导航栏就会消失。当我旋转回纵向方式时,我也没有恢复导航栏。
PS:我的 mainiPhone.xib 文件有 2 个视图(一个在纵向模式下,一个在横向模式下)。我像这样切换 mainiPhone.m 内的视图:
- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation) interfaceOrientation 持续时间: (NSTimeInterval) period {
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。
我做错了什么? 预先非常感谢您!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论