我有一個MovieViewController作爲UINavigationController的子模塊。我使用MPMoviePlayerViewController來播放由MovieViewController觸發的視頻流,並且在該視頻視圖中,它可以將方向更改爲橫向或縱向。我需要的是,當我點擊完成按鈕時,MovieViewController再次轉到肖像模式,因爲它只支持肖像模式。僅在縱向模式下強制使用UINavigationController
下面是代碼
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger) supportedInterfaceOrientations {
return(UIInterfaceOrientationMaskPortrait);
}
- (BOOL) shouldAutorotate {
return FALSE;
}
但是當我點擊完成按鈕它的崩潰, 「preferredInterfaceOrientationForPresentation必須返回一個支持的接口方向!」
注:我以模態方式調用moviePlayer。
NSURL *movieURL = [NSURL URLWithString:@"URL"];
player =[[MyMoviePlayerViewController alloc]
initWithContentURL:movieURL];
[self presentViewController:player animated:YES completion:nil];
所以在調用它之後,會出現將會關閉視圖的按鈕。問題是當我在橫向模式下觀看電影並點擊完成按鈕時,它因爲我只有1個支持的界面(肖像)而崩潰。
考慮這種解決方案,它創建導航控制器上的類別,它其設置爲允許/ dissalowed方向http://stackoverflow.com/questions/26205269/force-view-controller-to-portrait-only – zonabi