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

前端之家收集整理的这篇文章主要介绍了ios – 旋转呈现的视图并锁定呈现视图控制器的方向前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在研究仅支持横向定位的iPad应用程序,我想允许一些呈现的视图控制器支持所有方向而不改变呈现视图控制器的方向.我支持 Xcode设置中的所有方向,除了颠倒.

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

ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC"];
    vc.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:vc animated:YES completion:nil];

我正在使用的代码允许显示视图控制器的方向:

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

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

你管应用程序在播放视频时提供相同的功能,任何想法它是如何工作的?

任何帮助都会感谢,谢谢.

解决方法

AppDelegate.m

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

if(_isAllModes)
    return UIInterfaceOrientationMaskAll;
else
    return UIInterfaceOrientationMaskPortrait;
}

你的ViewController.回转:

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

猜你在找的iOS相关文章