MPMoviePlayerController 和 iOS8 自定义控件
Posted
技术标签:
【中文标题】MPMoviePlayerController 和 iOS8 自定义控件【英文标题】:MPMoviePlayerController and custom controls iOS8 【发布时间】:2014-09-29 17:48:14 【问题描述】:- (UIView*)getContainerView
UIView *playerControls = (self.videoPlayer.view ? self.videoPlayer.view : self.view);
NSString* containerViewName = [self getContainerViewName]; **//@"MPSwipableView" gets returned**
for(UIWindow* tempWindow in [[UIApplication sharedApplication]windows])
for(UIView* tempView in [tempWindow subviews])
if ([[tempView description] rangeOfString:containerViewName].location != NSNotFound)
playerControls = tempView;
break;
if(playerControls == nil)
NSLog(@"player ERROR : movieDidEnterFullScreen , no view named %@ was found",containerViewName);
return playerControls;
- (void)addCustomControls
//...//
UIView *controlsPlaceholder = [self getContainerView];
if (controlsPlaceholder)
if (![controlsPlaceholder.subviews containsObject:self.customControls.view])
[controlsPlaceholder addSubview:self.customControls.view];
else
[controlsPlaceholder bringSubviewToFront:self.customControls.view];
//...//
if (self.tapGestureRecognizer == nil)
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
self.tapGestureRecognizer.delegate = self;
if ([Device] is_iPad])
[self.customControls.view addGestureRecognizer:self.tapGestureRecognizer];
else
[self.videoPlayer.view addGestureRecognizer:self.tapGestureRecognizer];
====================
我的问题只出在播放器全屏时的 ios8 上。 handleTapGesture: 没有被调用,当我进入全屏模式时,自定义控件视图也会消失。
有什么想法吗? 提前致谢!
【问题讨论】:
【参考方案1】:“getContainerViewName”方法有如下变化:
- (NSString*)getContainerViewName
if ([[PSDeviceInfo sharedInstance] is_iOS5])
return @"UILayoutContainerView";
if ([[PSDeviceInfo sharedInstance] is_iOS6])
return @"MPSwipableView";
if ([[PSDeviceInfo sharedInstance] is_iOS7])
return @"MPSwipableView";
if ([[PSDeviceInfo sharedInstance] is_iOS8])
return@"MPSwipableView";
NSLog(@"player ERROR : getContainerViewName");
return nil;
- (NSString*)getContainerViewName
if ([[PSDeviceInfo sharedInstance] is_iOS5])
return @"UILayoutContainerView";
if ([[PSDeviceInfo sharedInstance] is_iOS6])
return @"MPSwipableView";
if ([[PSDeviceInfo sharedInstance] is_iOS7])
return @"MPSwipableView";
if ([[PSDeviceInfo sharedInstance] is_iOS8])
if (self.playerIsInfullScreen)
return @"UIInputSetContainerView";
else
return@"MPSwipableView";
NSLog(@"player ERROR : getContainerViewName");
return nil;
自定义控件视图将响应触摸并且它也将是可见的。希望这会对有需要的人有所帮助。
【讨论】:
感谢@Drd,这帮助我摆脱了 MPMoviePlayerController 形的绝望深渊 :)以上是关于MPMoviePlayerController 和 iOS8 自定义控件的主要内容,如果未能解决你的问题,请参考以下文章
MPMoviePlayerController 慢速前进和后退运动[重复]
MPMoviePlayerController 与 MPMoviePlayerViewController
MPMoviePlayerController 的初始和结束时间属性...破坏性?
MPMoviePlayerController 和 UIWebView