具有自定义叠加层的AVPlayerViewController [英] AVPlayerViewController with custom overlay
问题描述
从MPMoviePlayer迁移到AVkit使我遇到了阻止问题.
Migrating to AVkit from MPMoviePlayer has brought me to a blocking issue.
我需要在AVPlayerViewController上显示一个自定义tableView. 我可以在此tableview槽
I need to display a custom tableView over the AVPlayerViewController. I can this tableview trough
[self.avVideoPlayer.contentOverlayView addsubiew:self.mycustomTableView]
它是可见的,但没有收到任何轻击/滑动事件.
and it is visible but it doesn't receive any tap/swipe events.
为什么会发生这种情况,或者如何将表视图添加到即使在全屏模式下也将接收触摸事件的地方?
Any ideas why this happens or how can I add the table view in a place where it would receive the touch events even in the fullscreen mode?
推荐答案
[self.view addSubview:btn];
这会将按钮添加到最小化的播放器中.
This will add the button in the minimised player.
对于全屏场景,现在您需要为videoBounds添加观察者,这是我的代码:
Now for the fullscreen scenario you need to add an observer for the videoBounds, here is my code:
[self.avVideoPlayer addObserver:self forKeyPath:@"videoBounds" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL];
现在来了不那么漂亮的部分:
Now here comes the not so pretty part:
- (void)observeValueForKeyPath: (NSString*) path
ofObject: (id)object
change: (NSDictionary*)change
context: (void*)context {
NSLog(@"SOME OBSERVER DID THIS: %@ , %@",object,change);
if ([self playerIsFullscreen]) {
for(UIWindow* tempWindow in [[UIApplication sharedApplication]windows]){
for(UIView* tempView in [tempWindow subviews]){
if ([[tempView description] rangeOfString:@"UIInputSetContainerView"].location != NSNotFound){
UIButton *testB = [[UIButton alloc] initWithFrame: CGRectMake(20, 20, 400, 400)];
testB.backgroundColor = [UIColor redColor];
[testB addTarget:self action:@selector(buttonTouch) forControlEvents:UIControlEventTouchDown];
[tempView addSubview:testB];
break;
}
}
}
}
}
我知道这不是一个好方法,但这是我设法添加一些自定义UI的唯一方法,该UI还可以接收播放器上的触摸事件.
I know this is a not a nice way to do it, but it is the only way I managed to add some custom UI that also receives touch events on the player.
干杯!
这篇关于具有自定义叠加层的AVPlayerViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!