我有一個支持所有接口方向的iPhone應用程序(iOS6 +)。但是,當MPMoviePlayerController播放全屏視頻時,只應支持橫向。強制整個屏幕上的橫向方向MPMoviePlayerController在退出全屏時阻止了正確的旋轉
我在Stack Overflow上找到了下面的解決方案,它工作。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
...
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.landscapeOnlyOrientation) {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskAll;
}
- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
self.landscapeOnlyOrientation = YES;
}
- (void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
self.landscapeOnlyOrientation = NO;
}
然而,一個惱人的問題仍然存在,即如果視頻中退出縱向全屏(強制橫向播放後),基本觀點不旋轉回。我必須手動將設備旋轉到風景並返回到肖像以觸發更新方向。有什麼辦法可以通過編程方式觸發這種更新?
下面的一組截圖應該說明我的意思:
注:由於種種原因,使用MPMoviePlayerViewController是不可能的。
我幾個月前提交的bug蘋果在這個問題上。我建議你這樣做。問題是沒有諮詢底層視圖控制器的方向方法。 – matt
任何有關解決方法的建議? – svth
不可以。您可以嘗試阻止使用全屏模式。或者不要使用MPMoviePlayerController。基本上,這只是蘋果公司的一個大不相干的事情,開發人員需要在他們修復之前一直保持這種狀態。 – matt