2017-07-18 120 views
3

我正在研究仅支持横向方向的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; 
} 

你管的应用提供同种功能的同时播放视频,任何想法如何工作?

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

回答

0

AppDelegate.m

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

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

您的视图控制器。旋转:

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

我有一个类似的问题,但项目设置覆盖您以编程方式应用单个ViewController设置。我做了什么来解决这个问题被留在项目设置的唯一分钟可以接受的方向,它在AppDelegate.m像下面

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window //newUX 
{ 
    return UIInterfaceOrientationMaskAll; 
} 

你可以做的更好反正延伸,例如,如果要启用所有方向只有在一个特定的场景,只是说如果在堆栈最后的viewController是“全” - 酮,像下面

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window //newUX 
{ 
    if([self.navController.viewControllers.lastObject isKindOfClass:[MyAllOrientationVC class]])//newUX 
     return UIInterfaceOrientationMaskAll; 
    else 
     return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight; 
} 
+1

我不使用导航控制器还,如果我改变的方向是改变两个视图控制器的方向,我只想**呈现视图控制器**方向更改不**呈现视图控制器**(因为我通过设置呈现视图控制器样式**表单**所以两个视图控制器都可见) – user2493047