Portrait and Landscape mode in iOS6

后端 未结 3 912
陌清茗
陌清茗 2020-12-05 22:08

When updating my app to iOS6 standard the portrait / landscape is gone. Ir worked perfectly when I was building with Xcode 3. But now using latest Xcode and latest SDK the r

3条回答
  •  半阙折子戏
    2020-12-05 22:35

    How to support one or more landscape controllers in app that is portrait mainly in ios6:

    1) in AppDelegate

     - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
        {
            UINavigationController* ns = (UINavigationController*)self.window.rootViewController;
            if (ns) {
                UIViewController* vc = [ns visibleViewController];
    //by this UIViewController that needs landscape is identified
                if ([vc respondsToSelector:@selector(needIos6Landscape)])
                    return [vc supportedInterfaceOrientations];
    
            }
            return UIInterfaceOrientationMaskPortrait; //return default value
        }
    

    2) in UIView controller(s) that needs landscape (or portrait+lanscape etc):

    //flag method
    -(void)needIos6Landscape {
    }
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    

    3) in controllers, to which you can RETURN from controllers, that can be rotated in landscape - this is important, otherwise they remaind landscape on return from landscape-enabled VC.

    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    4) (maybe not needed, but for sure..) - subclass navigation controller(s) you using, and add:

    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        UIViewController* vc = [self visibleViewController];
        if (vc) {
            if ([vc respondsToSelector:@selector(needIos6Landscape)]) {
                 return [vc supportedInterfaceOrientations];
            }
        }
        return UIInterfaceOrientationMaskPortrait;
    }
    

    The important step is to ask for orientation only controllers from your app, because during transition between controllers, for some time there is some system controller as root, and will return incorrect value (this took me 2 hrs to find out, it was reason it was not working).

提交回复
热议问题