简体   繁体   English

IOS6轮换问题

[英]IOS6 rotation issue

I know you have to use the new rotation methods for IOS6, but it seems the method I've written doesn't work. 我知道你必须为IOS6使用新的旋转方法,但似乎我写的方法不起作用。

I setted my plist file to allow all rotation but not portraitUpsideDown 我设置我的plist文件以允许所有旋转但不允许portraitUpsideDown

I then had the following in my appDelegate : 然后我在appDelegate中有以下内容:

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

Then in my rootView, to push to another controller, I have: 然后在我的rootView中,推送到另一个控制器,我有:

WebViewViewController *webController = [[JBWebViewViewController alloc] init];
webController.urlString =   urlName;
[self.navigationController pushViewController:webController animated:YES];

And In the web controller I have: 在网络控制器中,我有:

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

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. 我想要做的是,在根视图中允许3次旋转,但是当切换到Web视图时(注意我确实推导航,不添加子视图),我只想允许纵向视图。

Someone help me please 请有人帮帮我

-------UPDATE---------- -------更新----------

I've created my own navController subclass of UINavigationController, I have an BOOL landscapeModeOn that I can setup to tell auto rotation specs 我已经创建了自己的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;
  }
}

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

--------------------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 --------------------参考最佳答案的引用对于IOS6,苹果现在专注于使用Storyboard的AutoLayout和新的旋转定义,很难修复一些基于ios 4.3和ios 5编码结构的IOS6微小错误

From applefreak, his suggestion hinted on: 来自applefreak,他的建议暗示:

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 虽然手动旋转视图似乎很难没有任何错误,但它似乎是我现在尝试的唯一解决方案,将发布更多一旦解决

For your situation you will have to subclass your NavigationController and add the shouldAutorotate and supportedInterfaceOrientations methods to it. 根据您的情况,您必须为您的NavigationController创建子类,并将shouldAutorotate和supportedInterfaceOrientations方法添加到其中。 iOS6 now asks your navigation stack in the reverse order to iOS5 so it will ask your NavigationController first and if that returns YES it won't even consult with it's child view controllers. iOS6现在以与iOS5相反的顺序询问您的导航堆栈,因此它将首先询问您的NavigationController,如果返回YES,它甚至不会咨询它的子视图控制器。 To fix that you have to add the logic yourself to do this 要解决此问题,您必须自己添加逻辑来执行此操作

So in your subclassed navigation controller you manually ask your current viewcontroller it's autorotation abilities: 因此,在您的子类导航控制器中,您手动询问当前的viewcontroller它的自动旋转能力:

- (BOOL)shouldAutorotate
{
    return self.topViewController.shouldAutorotate;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return self.topViewController.supportedInterfaceOrientations;
}

and in your individual viewcontrollers you can now implement those functions and have them return the values you want which you have defined in your question. 在您的个人视图控制器中,您现在可以实现这些功能,并让它们返回您在问题中定义的所需值。

I hope this makes sense. 我希望这是有道理的。

Following code is wrong! 以下代码错了!

- (BOOL)shouldAutorotate{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

Remember that supportedInterfaceOrientations gets called only if shouldAutoRotate returns YES. 请记住,仅当shouldAutoRotate返回YES时才会调用supportedInterfaceOrientations。 Now root view controllers decides whether it's children rotates or not. 现在,根视图控制器决定它的子节点是否旋转。

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! 在你的情况下,我建议你的self.viewController有一个基类控制器,并将self.viewController设置为root视图控制器而不是navigationController,否则不会调用旋转方法! I ran into this same issue. 我遇到了同样的问题。 You should have a HAS-A relationship with base view controller and it's children. 您应该与基本视图控制器及其子级具有HAS-A关系。 Return Yes/No from ShouldAutoRotate based on active children and same for supported orientation. 根据活动子项从ShouldAutoRotate返回是/否,对于支持的方向,返回相同。 If you follow this architecture then it would be consistent for complex App. 如果您遵循这种架构,那么它对于复杂的应用程序将是一致的。

For example in your case BaseviewController should return YES from shouldAutoRotate and returns UIInterfaceOrientationPortrait from supported orientation delegate when webviewController is active. 例如,在您的情况下,BaseviewController应该从shouldAutoRotate返回YES,并在webviewController处于活动状态时从支持的方向委托返回UIInterfaceOrientationPortrait。 I hope this makes sense. 我希望这是有道理的。

It common code for iOS5 and iOS6 它是iOS5和iOS6的通用代码

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIInterfaceOrientationIsLandscape(interfaceOrientation))  
    { 
        // here to  implement landscope code
    }

    else
    {  
        // here to  implement setframePortrait
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM