2013-02-26 125 views
4

我提出一個模式的看法與代碼:縱向方向除了在模式視圖控制器

[self presentViewController:movieViewController animated:YES completion:^{ 
    // completed 
}]; 

內movieViewController,控制器被駁回用:

[self dismissViewControllerAnimated:YES completion:^{ 
    // back to previous view controller 
}]; 

在那時,我所有的視圖控制器都可以以縱向和兩種風景方向進行查看。

除了模態視圖控制器之外,我將如何限制所有視圖控制器爲縱向?所以模態視圖控制器可以在三個方向中看到,其他所有方面都可以看到。

+0

你打算使用iOS 6還是5? – iiFreeman 2013-02-26 22:25:19

+0

iOS 6及以上 – cannyboy 2013-02-27 00:40:29

回答

20

在的appDelegate:

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
     return UIInterfaceOrientationMaskAllButUpsideDown; 
    } 

特殊的UINavigationController子類(如果您在使用導航控制器)與方法:

- (NSUInteger)supportedInterfaceOrientations { 
    if (self.topViewController.presentedViewController) { 
     return self.topViewController.presentedViewController.supportedInterfaceOrientations; 
    } 
    return self.topViewController.supportedInterfaceOrientations; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return self.topViewController.preferredInterfaceOrientationForPresentation; 
} 

每個視圖控制器應該回到它自己支持的方向和優先呈現定向:

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return UIInterfaceOrientationPortrait; 
} 

我的應用程序在肖像,但視頻播放器打開爲模態vc:

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return UIInterfaceOrientationLandscapeLeft; 
} 

它適合我,希望它有幫助!

+0

我不得不在我的視頻播放器的supportedInterfaceOrientations UIInterfaceOrientationMaskLandscapeLeft強制景觀,以使其工作。否則我會得到崩潰。但視頻是爲了觀看風景,不是沒有probs。 – cannyboy 2013-02-27 17:55:55

+0

不,您需要將所有支持的方向作爲蒙版返回,並返回一個橫向方向作爲演示文稿的首選方向。 – iiFreeman 2013-02-27 19:47:45

+0

愛你! :)效果很好 – 2014-01-31 08:50:16

相關問題