简体   繁体   English

在iOS 6上处理iDevice旋转

[英]Handling iDevice rotation on iOS 6

I'm having trouble figuring out how to handle device rotation on iOS 6. I have three things that need to change separately when the device is rotated. 我在弄清楚如何在iOS 6上处理设备旋转时遇到麻烦。当设备旋转时,我有三件事需要分别更改。

  • I have a parent UIViewController that handles multiple sub UIViewControllers or UINavigationControllers (Its basically a custom UITabBarController). 我有一个父UIViewController,它处理多个子UIViewControllers或UINavigationControllers(它基本上是一个自定义UITabBarController)。 I do not want this to rotate. 我不希望这个旋转。
  • Each of these sub view controllers, will either rotate or not rotate depending on its own settings. 这些子视图控制器中的每一个将根据其自身的设置旋转或不旋转。 (I want some to rotate and some to not). (我想要一些旋转而有些则不旋转)。
  • In the tab bar, I want each tab icon (a UIView) to rotate to the orientation. 在选项卡栏中,我希望每个选项卡图标(一个UIView)旋转到方向。

How would I go about making this happen in iOS 6, I got everything working in iOS 5. 我将如何在iOS 6中实现这一目标,在iOS 5中一切正常。

Here is what I have so far: 这是我到目前为止的内容:

In the parent UIViewController: 在父UIViewController中:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (BOOL)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

In the sub view controllers: 在子视图控制器中:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
        return YES;
}

- (BOOL)shouldAutorotate
{
        return YES;
}

- (BOOL)supportedInterfaceOrientations
{
        return UIInterfaceOrientationMaskAll;
}

There's a bit more to this to support iOS6 correctly. 可以进一步支持iOS6。 The iOS 6 Release Notes sketch things out: iOS 6发行说明概述了以下内容:

https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html

This bit might be useful: 这一点可能有用:

For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. 为了兼容性,仍然实现shouldAutorotateToInterfaceOrientation:方法的视图控制器不会获得新的自动旋转行为。 (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method. (换句话说,它们不会退回到使用应用程序,应用程序委托或Info.plist文件来确定受支持的方向。)相反,应该使用shouldAutorotateToInterfaceOrientation:方法来合成supportedInterfaceOrientations方法将返回的信息。 。

But you should also take a look at Session 236 from WWDC 2012 - The Evolution of View Controllers. 但是您也应该看看WWDC 2012的Session 236-视图控制器的演变。

If you want to support different orientation in navigation stack, you must subclass UINavigationController first and override supportedInterfaceOrientations. 如果要在导航堆栈中支持其他方向,则必须首先将UINavigationController子类化,并重写supportedInterfaceOrientations。

- (NSUInteger)supportedInterfaceOrientations
{
    //I want to support portrait in ABCView at iPhone only.
    //and support all orientation in other views and iPad.

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
    {
        // find specific view which you want to control.
        if ([[self.viewControllers lastObject] isKindOfClass:[ABCView class]])
        {
            return UIInterfaceOrientationMaskPortrait;
        }
    }

    //support all
    return UIInterfaceOrientationMaskAll;
}

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

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