我有一个iPhone应用程序(iOS6+),支持所有界面方向。但是,当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;
}
然而,一个烦人的问题仍然存在,即如果视频在强制横屏后退出全屏模式进入竖屏模式,则底层视图不会旋转回来。我必须手动将设备旋转到横向再旋转回竖向以触发方向更新。有没有办法通过编程来触发这种更新呢?以下一组屏幕截图应说明我的意思:
NB:由于各种原因,不可能使用MPMoviePlayerViewController。