IOS6轮换问题 [英] IOS6 rotation issue

查看:90
本文介绍了IOS6轮换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你必须为IOS6使用新的旋转方法,但似乎我写的方法不起作用。

I know you have to use the new rotation methods for IOS6, but it seems the method I've written doesn't work.

我设置了我的plist文件允许所有轮换,但不是portraitUpsideDown

I setted my plist file to allow all rotation but not portraitUpsideDown

然后我在 appDelegate 中有以下内容:

I then had the following in my appDelegate:

self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window setRootViewController:navController];  //add nav controller to be the root view

然后在我的rootView中,推送到另一个控制器,我有:

Then in my rootView, to push to another controller, I have:

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视图时(注意我确实推送导航,而不是添加子视图),我只想允许纵向视图。

What I want do, is to allow 3 rotations in the root view, but when switch to the web view(note I do push navigation, not add subview), I only want to allow portrait view.

有人请帮助我

-------更新----------

-------UPDATE----------

我创建了自己的navController UINavigationController的子类,我有一个BOOL landscapeModeOn我可以设置告诉自动旋转规格

I've created my own navController subclass of UINavigationController, I have an BOOL landscapeModeOn that I can setup to tell auto rotation specs

#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;
  }
}

在子视图加载中,我这样做:

IN the subviews loading, I do:

- (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的一些小错误编码结构

--------------------Refer to best answer's quote For IOS6, apple is now focusing on using the Storyboard's AutoLayout together with the new rotation definitions, it is difficult to fix some tiny bugs for IOS6 based on the ios 4.3 and ios 5 coding structure

来自applefreak,他的建议暗示:

From applefreak, his suggestion hinted on:


主要挑战在你的情况下不处理方向。实际上它将不同的视图控制器锁定到特定的方向

A main challenge in your case is not handling the orientations. Actually it's locking the different view controllers to particular orientation

虽然手动旋转视图似乎很难没有任何错误,但它似乎是只有我正在尝试的解决方案,一旦解决就会发布更多

Although manual rotate view seems really hard to do without any bugs, but it seems the only solution I am now trying, will post more once solved

推荐答案

以下代码错误!

- (BOOL)shouldAutorotate{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

请记住,仅当shouldAutoRotate返回YES时才会调用supportedInterfaceOrientations。现在,根视图控制器决定它的子节点是否旋转。

Remember that supportedInterfaceOrientations gets called only if shouldAutoRotate returns YES. Now root view controllers decides whether it's children rotates or not.

在你的情况下,我建议你的self.viewController有一个基类控制器,并将self.viewController设置为root视图控制器而不是navigationController,否则旋转方法将不会调用!我遇到了同样的问题。您应该与基本视图控制器及其子级具有HAS-A关系。根据活动子项从ShouldAutoRotate返回是/否,对于支持的方向,返回相同。如果你遵循这个架构,那么它对于复杂的应用程序将是一致的。

In your case I would suggest to have a base class controller to your self.viewController and set self.viewController to root view controller not navigationController otherwise rotation methods won't be invoked! I ran into this same issue. You should have a HAS-A relationship with base view controller and it's children. Return Yes/No from ShouldAutoRotate based on active children and same for supported orientation. If you follow this architecture then it would be consistent for complex App.

例如在你的情况下,BaseviewController应该从shouldAutoRotate返回YES并且当webviewController是时,从支持的方向委托返回UIInterfaceOrientationPortrait活性。我希望这是有道理的。

For example in your case BaseviewController should return YES from shouldAutoRotate and returns UIInterfaceOrientationPortrait from supported orientation delegate when webviewController is active. I hope this makes sense.

这篇关于IOS6轮换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆