Launching into portrait-orientation from an iPhone 6 Plus home screen in landscape orientation results in wrong orientation

前端 未结 13 1690
南方客
南方客 2020-12-22 23:21

The actual title for this question is longer than I can possibly fit:

Launching an app whose root view controller only supports portrait-orientation but which otherw

13条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-22 23:33

    I had a very similar problem. I wanted to force portrait mode everywhere except for playing back videos.

    What I did was:

    1) to force the app orientation to be in portrait in the AppDelegate:

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        if ([window.rootViewController.presentedViewController isKindOfClass:[MPMoviePlayerViewController class]])
        {
            return UIInterfaceOrientationMaskAll;
        }
        return UIInterfaceOrientationMaskPortrait;
    }
    

    2) launching an empty modal view controller fixed the problem in my case. I launch it in the viewDidLoad of the first view controller that is on the root of my NavigationViewController (the first view controller visible after the application launches):

    - (void)showAndHideNamelessViewControllerToFixOrientation {
        UIViewController* viewController = [[UIViewController alloc] init];
        [self presentViewController:viewController animated:NO completion:nil];
        [viewController dismissViewControllerAnimated:NO completion:nil];
    }
    

提交回复
热议问题