首先,你需要在你的plist所有的應用程序支持的方向,這可以在「常規」選項卡中完成的「部署信息」下的項目設置,例如: ![enter image description here](https://i.stack.imgur.com/tKnFc.png)
然後,您可以使用的方法supportedInterfaceOrientations
,
我假設你是模態呈現視圖控制器,所以只需將其覆蓋,在呈現的viewController,這就需要只在肖像使用:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
,並在您提交的viewController,也應支持橫向,用途:(或任何方向面膜你想)
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
PS - 有對的viewController不同的行爲有模式呈現併爲推動在navigationController堆棧的viewController:
- modalViewController將調用自己的
supportedInterfaceOrientations
,並將支持這些方向
- pushingViewController將調用其導航控制器
supportedInterfaceOrientations
,並將支持這些方向。
所以,如果你是模態呈現的viewController,你需要重寫自己的supportedInterfaceOrientations
,但如果你把這個的viewController,您需要設置一些BOOL屬性在navigationController,所以它會知道哪個方向來支持。 我建議你以模態方式呈現這個viewController,對於不同的設備方向使用modalViewController更自然。
P.S#2:約shouldAutorotate
:如果返回 'NO',比supportedInterfaceOrientations
不叫,所以返回 'YES'。它只是說,如果在設備旋轉時自動旋轉。如果返回「NO」,則需要顯式旋轉viewController。
那麼我希望我幫助,並沒有寫是完全不視爲你問一個答案... :)
http://stackoverflow.com/questions/12775265/ios-6-shouldautorotate不要被稱爲嘗試這個 –
@Dheeraj辛格不幸的是沒有任何方法叫。 –
我們已經爲navigationController做了同樣的事情 self.window.rootViewController = self.objNavigationController; –