【发布时间】:2015-09-01 12:38:56
【问题描述】:
我正在研究方向和电影播放器。功能如下:
如果我打开 MPMoviePlayer 的全屏模式,那么它应该只以横向模式打开。
如果我将设备旋转到横向,它将自动启动 MPMoviePlayer 的全屏模式
当我关闭它时,它应该再次回到纵向模式
MPMoviePlayer 的全屏模式或将设备旋转到纵向模式。
现在的问题是,它在设备旋转到横向模式时进入全屏模式
但是在回来的时候,UI 没有正确转换为纵向模式。
此问题仅适用于 iOS 8.1、8.2。它在 iOS 7.* 和 8.3、8.4 中运行良好。
请查看附加屏幕:
全屏前:
全屏后:
回到纵向模式:
我已使用此代码来处理方向:
allowRotation 是在AppDelegate.h 文件中声明的布尔属性
//在App Delegate中为电影播放器方向事件添加观察者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
// 观察者方法
- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
allowRotation = YES;
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
allowRotation = NO;
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] && ![[self.window.rootViewController presentedViewController] isBeingDismissed]) || allowRotation)
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
else{
allowRotation= NO;
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskPortrait;
}
请帮我解决这个问题。
【问题讨论】:
-
你是怎么解决的?
标签: ios iphone orientation mpmovieplayercontroller uiinterfaceorientation