3 回答

TA貢獻1817條經驗 獲得超14個贊
這應該可以工作,類似于iOS 6之前的版本,但帶有UINavigationController:
UIViewController *portraitViewController = [[UIViewController alloc] init];
UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:portraitViewController];
[self.navigationController presentModalViewController:nc animated:NO];
[self.navigationController dismissModalViewControllerAnimated:NO];
我先打這個,再推下一個UIViewController。UIViewController即使當前UIViewController處于橫向模式,它也會強制將下一個按下的按鈕顯示為縱向模式(也適用于縱向到橫向)。適用于iOS 4 + 5 + 6。

TA貢獻1828條經驗 獲得超3個贊
我認為最好的解決方案是堅持使用Apple官方文檔。因此,據此我使用以下方法,并且在iOS 5和6上一切正常。在我的VC中,我重寫了以下方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
適用于iOS 6的方法,第一種方法返回支持的方向遮罩(如其名稱所示)
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
第二個告訴您的VC,當要顯示VC時,這是首選的界面方向。
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
只需將Portrait更改為所需的方向即可;)此解決方案運行流暢,我不喜歡圍繞此簡單解決方案創建宏和其他內容的想法。希望能有所幫助...
- 3 回答
- 0 關注
- 659 瀏覽
添加回答
舉報