3 回答

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

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