phi*_*530 5 iphone rotation uinavigationcontroller ios ios6
我知道你必须为IOS6使用新的旋转方法,但似乎我写的方法不起作用.
我设置我的plist文件以允许所有旋转但不允许portraitUpsideDown
然后我在appDelegate中有以下内容:
self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window setRootViewController:navController]; //add nav controller to be the root view
Run Code Online (Sandbox Code Playgroud)
然后在我的rootView中,推送到另一个控制器,我有:
WebViewViewController *webController = [[JBWebViewViewController alloc] init];
webController.urlString = urlName;
[self.navigationController pushViewController:webController animated:YES];
Run Code Online (Sandbox Code Playgroud)
在网络控制器中,我有:
#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;
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是,在根视图中允许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;
}
}
Run Code Online (Sandbox Code Playgroud)
在子视图加载中,我做:
- (void)viewWillAppear:(BOOL)animated{
//get nav controller and turn off landscape mode
JBNavController *navController = (JBNavController*)self.navigationController;
[navController setLandscapeModeOn:NO];
[navController shouldAutorotate];
}
Run Code Online (Sandbox Code Playgroud)
--------------------参考最佳答案的引用对于IOS6,苹果现在专注于使用Storyboard的AutoLayout和新的旋转定义,很难修复一些基于ios 4.3和ios 5编码结构的IOS6微小错误
来自applefreak,他的建议暗示:
您的案例中的主要挑战是不处理方向.实际上,它将不同的视图控制器锁定到特定方向
虽然手动旋转视图似乎很难没有任何错误,但它似乎是我现在尝试的唯一解决方案,将发布更多一旦解决
根据您的情况,您必须为您的NavigationController创建子类,并将shouldAutorotate和supportedInterfaceOrientations方法添加到其中.iOS6现在以与iOS5相反的顺序询问您的导航堆栈,因此它将首先询问您的NavigationController,如果返回YES,它甚至不会咨询它的子视图控制器.要解决此问题,您必须自己添加逻辑来执行此操作
因此,在您的子类导航控制器中,您手动询问当前的viewcontroller它的自动旋转能力:
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
Run Code Online (Sandbox Code Playgroud)
在您的个人视图控制器中,您现在可以实现这些功能,并让它们返回您在问题中定义的所需值.
我希望这是有道理的.
下面的代码是错误的!
- (BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
请记住,仅当 shouldAutoRotate 返回 YES 时,supportedInterfaceOrientations 才会被调用。现在根视图控制器决定它的子视图是否旋转。
在你的情况下,我建议你的 self.viewController 有一个基类控制器,并将 self.viewController 设置为根视图控制器而不是 navigationController,否则旋转方法将不会被调用!我遇到了同样的问题。您应该与基本视图控制器及其子视图具有 HAS-A 关系。根据活动的子项从 ShouldAutoRotate 返回“是”/“否”,对于受支持的方向也是如此。如果您遵循此架构,那么对于复杂的应用程序来说它将是一致的。
例如,在您的情况下,当 webviewController 处于活动状态时,BaseviewController 应该从 shouldAutoRotate 返回 YES 并从支持的方向委托返回 UIInterfaceOrientationPortrait 。我希望这是有道理的。
| 归档时间: |
|
| 查看次数: |
7746 次 |
| 最近记录: |