除模态视图控制器外的所有视图控制器中的纵向方向

can*_*boy 5 objective-c uiviewcontroller uiinterfaceorientation ios

我正在使用代码呈现模态视图:

 [self presentViewController:movieViewController animated:YES completion:^{
     // completed
 }];
Run Code Online (Sandbox Code Playgroud)

在movieViewController中,控制器被解雇:

[self dismissViewControllerAnimated:YES completion:^{
    // back to previous view controller
}];
Run Code Online (Sandbox Code Playgroud)

目前,我的所有视图控制器都可以纵向和两个横向方向查看.

除了模态视图控制器之外,如何将所有视图控制器限制为纵向?因此,可以在三个方向中看到模态视图控制器,而在一个方向中可以看到其他所有内容.

iiF*_*man 21

在appDelegate中:

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
Run Code Online (Sandbox Code Playgroud)

特殊的UINavigationController子类(如果使用导航控制器)与方法:

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return self.topViewController.preferredInterfaceOrientationForPresentation;
}
Run Code Online (Sandbox Code Playgroud)

每个视图控制器应该返回它自己支持的方向和首选的显示方向:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)

我的应用程序以纵向工作,但视频播放器以模态vc打开:

 - (NSUInteger)supportedInterfaceOrientations {
     return UIInterfaceOrientationMaskAllButUpsideDown;
 }

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
     return UIInterfaceOrientationLandscapeLeft;
 }
Run Code Online (Sandbox Code Playgroud)

它对我来说很完美,希望它有所帮助!