2016-03-02 52 views
1

我想只更改一個UiViewController的設備方向。我的第一個UiViewController的名字是VideoLaunch。我首先需要在此UiViewController中使用橫向方向。當我通過另一個uiviewcontroller時,我將名稱爲「is」的靜態值更改爲不同於nil。當我在調試模式下運行,我看到Objective-C僅更改一個UiViewController的設備方向

否則返回UIInterfaceOrientationMaskPortrait

這條線運行。但方向不會改變。

AppDelegate.m

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    if([VideoLaunch is] == nil) 
     return UIInterfaceOrientationMaskLandscape; 

    else return UIInterfaceOrientationMaskPortrait; 
} 
+1

檢查此問題http://stackoverflow.com/questions/27009979/ios-lock-a-specific-uiviewcontroller-to-a-specific-orientation – Rishab

回答

4

您需要重寫下面的方法

- (BOOL)shouldAutoRotate 

回報是爲您希望允許旋轉的一個。

然後,也覆蓋supportedDeviceOrientations並指定你想在那裏。例如:

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskAll; 
} 

並確保您在目標的常規設置中允許正確的方位。