我有一个AVPlayerViewController,它将在它上面有一些视图(仅当它在全屏时)。视图上有手势识别器(这些工作)。问题是,当用户点击其中一个视图(它们是不可见的)时,播放器也不会接收到触摸......我需要播放器显示播放器控件然后...
这就是我添加视图的方式
_topHelperView = [[UIView alloc] init];
_topHelperView.backgroundColor = [UIColor purpleColor];
_middleHelperView = [[UIView alloc] init];
_middleHelperView.backgroundColor = [UIColor redColor];
[self setHelperFrames];
_topTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleHelperTapGesture:)];
_topTapGestureRecognizer.delegate = self;
_topTapGestureRecognizer.cancelsTouchesInView = NO;
_middleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleHelperTapGesture:)];
_middleTapGestureRecognizer.cancelsTouchesInView = NO;
_middleTapGestureRecognizer.delegate = self;
我还实现了委托:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return YES;
}
// this enables you to handle multiple recognizers on single view
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
NSLog(@"should Handle simultaneously %@ %@",gestureRecognizer,otherGestureRecognizer);
return YES;
}
这不起作用..当点击任一视图时,播放器不显示控件..它只在直接点击时显示它们。 对此有何解决方法?
答案 0 :(得分:1)
当视图(实际上是UIResponder)响应时,触摸事件停止。因此,如果您在AVPlayerViewController顶部的视图上附加了手势识别器,则手势识别器将捕获事件,而AVPlayerViewController则不会。这是设计的。
为什么不让您的视图向AVPlayerViewController发送消息以响应用户的手势? AVPlayerViewController有一个属性showsPlaybackControls。如果您希望播放器显示其控件,请将其设置为YES。