我的应用也有这个问题,它支持多个 iOS 版本,但这个问题确实只在 iOS 8 上可见。
我的代码在MPMovieControlStyleEmbedded 和MPMovieControlStyleNone 之间切换MPMoviePlayerController 的controlStyle,这是使用UIDeviceOrientationDidChangeNotification 触发的。我不得不承认我以编程方式旋转我的播放器,我不旋转应用程序;这可能是这个问题的根源。我以纵向显示控件,并以横向隐藏它们。
我显然分两步解决了它。我没有在一个简单的应用程序中隔离这个问题,所以如果解决方案对每个人都不准确,我深表歉意。
首先,肮脏的部分,也许对于遇到这个问题的每个人来说都不是必需的,我解析了一些播放器子视图来处理 MPVideoPlaybackOverlayView 视图,以强制其可见或不可见。
// Helps to hide or show the controls over the player
// The reason of this method is we are programmatically rotating the player view, while not rotating the application
// On latest iOS, this leads to misbehavior that we have to take into account
-(void)showMPMoviePlayerControls:(BOOL)show
{
self.player.controlStyle = (show ? MPMovieControlStyleEmbedded : MPMovieControlStyleNone);
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8"))
{
// Workaround to avoid persistence of empty control bar
for(UIView *subView in self.player.backgroundView.superview.superview.subviews)
{
if ([subView isKindOfClass:NSClassFromString(@"MPVideoPlaybackOverlayView")]) {
subView.backgroundColor = [UIColor clearColor];
subView.alpha = (show ? 1.0 : 0.0);
subView.hidden = (show ? NO : YES);
}
}
}
}
但这还不够。可能是因为纵向模式有多个触发通知的方向(UIDeviceOrientationPortrait、UIDeviceOrientationFaceUp、...),因此控制样式更改请求。
所以我修复的第二步是处理这样一个事实,即如果我们已经处于正确的屏幕方向,则无需更改MPMoviePlayerController 的controlStyle。
就我而言,解决方案是验证状态栏是否隐藏,因为我将其隐藏在横向中:
// Set embedded controls only when there is a transition to portrait, i.e. if status bar was hidden
if ([[UIApplication sharedApplication] isStatusBarHidden]) {
[self showMPMoviePlayerControls:YES];
// and we show the status bar here
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
也许这里的重点是,如果 controlStyle 已经设置为想要的值,我们不应该设置它。
由于这为我解决了问题,我停止了调查。无论如何,我认为在大多数情况下它可能更简单。当然,这与controlStyle 在错误的时间更改或更改但已处于通缉状态这一事实有关。