以前,I asked about how to capture any touch input on an MPMoviePlayerController's view when the MPMovieControlStyle is set to MPMovieControlStyleNone。有人建议我可以使用UIGestureRecognizer来做到这一点。
我能够以这种方式使用手势识别器在屏幕上捕获双击,但不是单击。我用于此的代码如下:
///**********///
singleTapGestureRecognizer =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleClickOnMediaView:)];
singleTapGestureRecognizer.numberOfTapsRequired = 1;
[self.moviePlayer.view addGestureRecognizer:singleTapGestureRecognizer];
[singleTapGestureRecognizer release];
///**********///
为什么我无法使用此代码捕获MPMoviePlayerController视图上的单击?它是如何处理单个水龙头的?
答案 0 :(得分:0)
我知道这是一个有点老问题,但如果有人需要,这是一个解决方案。 要在同一视图上处理单击和双击,单击识别器必须等待双击识别器失败。像这样:
UITapGestureRecognizer* doubleTapRecon = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap)];
[doubleTapRecon setNumberOfTapsRequired:2];
[doubleTapRecon setDelegate:self];
[self.view addGestureRecognizer:doubleTapRecon];
UITapGestureRecognizer* singleTapRecon = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap)];
[singleTapRecon setNumberOfTapsRequired:1];
[singleTapRecon requireGestureRecognizerToFail:doubleTapRecon];
[singleTapRecon setDelegate:self];
[self.view addGestureRecognizer:singleTapRecon];
请注意,如果您不使用ARC,则必须注意内存管理。
答案 1 :(得分:0)
上述答案无法实现单击手势,您必须实施'UITapGestureRecognizerDelegate'并使用方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
因为'moviePlayer'也在使用点击手势,所以为了使我们的自定义单一点击只需要上面的方法。