旋转呈现视图并锁定呈现视图控制器的方向

use*_*047 5 iphone objective-c orientation ipad ios

我正在开发仅支持横向的 iPad 应用程序,我希望允许某些呈现的视图控制器支持所有方向,而无需更改呈现视图控制器的方向。除了颠倒之外,我支持 Xcode 设置中的所有方向。

我用来呈现视图控制器的代码

    ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC"];
    vc.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:vc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

我用来允许呈现的视图控制器方向的代码:

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

You Tube应用程序在播放视频时提供相同类型的功能,知道它是如何工作的吗?

任何帮助将不胜感激,谢谢。

小智 0

AppDelegate.m

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

if(_isAllModes)
    return UIInterfaceOrientationMaskAll;
else
    return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

你的视图控制器。回转:

[(AppDelegate*)([UIApplication sharedApplication].delegate) setIsAllModes:YES];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
Run Code Online (Sandbox Code Playgroud)