2017-07-18 115 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