【发布时间】:2012-09-16 09:38:45
【问题描述】:
我知道你必须使用IOS6的新旋转方法,但我写的方法似乎不起作用。
我将我的 plist 文件设置为允许所有旋转,但不允许 PortraitUpsideDown
然后我的 appDelegate 中有以下内容:
self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window setRootViewController:navController]; //add nav controller to be the root view
然后在我的 rootView 中,要推送到另一个控制器,我有:
WebViewViewController *webController = [[JBWebViewViewController alloc] init];
webController.urlString = urlName;
[self.navigationController pushViewController:webController animated:YES];
在网络控制器中我有:
#pragma mark - System Rotation Methods
//for any version before 6.0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//only allow landscape
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
/for 6.0+
- (BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
我想要做的是在根视图中允许 3 次旋转,但是当切换到 web 视图时(注意我是推送导航,而不是添加子视图),我只想允许纵向视图。
请大家帮帮我
-------更新---------
我已经创建了自己的 UINavigationController 的 navController 子类,我有一个 BOOL LandscapeModeOn,我可以设置它来告诉自动旋转规范
#pragma mark - System Rotation Methods
//for any version before 6.0
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
if (landscapeModeOn) {
return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
} else {
return interfaceOrientation == UIInterfaceOrientationPortrait;
}
}
//for 6.0+
- (NSUInteger)supportedInterfaceOrientations{
if (landscapeModeOn) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
- (BOOL)shouldAutorotate{
UIInterfaceOrientation ori = [UIDevice currentDevice].orientation;
if (landscapeModeOn) {
return ori != UIInterfaceOrientationPortraitUpsideDown;
} else {
return ori == UIInterfaceOrientationPortrait;
}
}
在加载子视图时,我会这样做:
- (void)viewWillAppear:(BOOL)animated{
//get nav controller and turn off landscape mode
JBNavController *navController = (JBNavController*)self.navigationController;
[navController setLandscapeModeOn:NO];
[navController shouldAutorotate];
}
--------------------参考最佳答案的报价 对于IOS6,苹果现在专注于使用Storyboard的AutoLayout和新的旋转定义,基于ios 4.3和ios 5的编码结构,IOS6的一些小bug很难修复
来自 applefreak,他的建议暗示:
在您的案例中,一个主要挑战是不处理方向。实际上它将不同的视图控制器锁定到特定的方向
虽然手动旋转视图似乎真的很难做到没有任何错误,但它似乎是我现在正在尝试的唯一解决方案,一旦解决就会发布更多
【问题讨论】:
-
根据 rooster117 的回答,这是我的解决方案:[stackoverflow.com/questions/12662240/…[1]:stackoverflow.com/questions/12662240/…
标签: iphone ios uinavigationcontroller rotation ios6