【发布时间】:2014-03-21 14:14:38
【问题描述】:
我有一个支持所有界面方向的 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;
}
但是,一个烦人的问题仍然存在,即如果视频以纵向退出全屏(在强制横向播放之后),则底层视图不会向后旋转。我必须手动将设备旋转为横向并返回纵向以触发方向更新。有什么方法可以以编程方式触发这种更新吗?
下面一组截图应该能说明我的意思:
注意:由于各种原因,无法使用 MPMoviePlayerViewController。
【问题讨论】:
-
几个月前我就这个问题向 Apple 提交了一个错误。我建议你这样做。问题是没有参考底层视图控制器的方向方法。
-
对解决方法有什么建议吗?
-
没有。您可以尝试阻止使用全屏模式。或者只是不使用 MPMoviePlayerController。基本上,这只是 Apple 的一个很大的不一致之处,开发人员需要坚持下去,直到他们修复它。
-
你检查过这个答案了吗?附有一个示例项目,可能会对您有所帮助。 stackoverflow.com/questions/15947349/…
标签: ios iphone objective-c mpmovieplayercontroller uiinterfaceorientation