本文介绍了MPMoviePlayerController的视图无法识别触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
_mediaPlayer = [[MPMoviePlayerController alloc] init];
_mediaPlayer.controlStyle = MPMovieControlStyleNone;
_mediaPlayer.shouldAutoplay = NO;
[_mediaPlayer.view setFrame: CGRectMake(5, 5, 600,400)];
[playerHolder addSubview: _mediaPlayer.view];
//
[self prepareScreenContentToPlay];
//
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleRollTap:)];
singleFingerTap.numberOfTapsRequired = 1;
[_mediaPlayer.view addGestureRecognizer:singleFingerTap];
[singleFingerTap release];
手势识别器的动作方法:
And action method for gesture recognizer:
-(void)handleRollTap:(UITapGestureRecognizer*)sender{
NSLog(@"%@", @"touch");
}
MPMoviePlayerController工作正常。另外我想处理MPMoviePlayerController视图上的触摸,但 handleRollTap
从未调用过。为什么MPMoviePlayerController的视图不适用于UITapGestureRecognizer?
MPMoviePlayerController works fine. In addition I want to handle touch on MPMoviePlayerController view but handleRollTap
never called. Why MPMoviePlayerController's view not works with UITapGestureRecognizer?
好的。如果 singleFingerTap.numberOfTapsRequired = 2;
那么一切正常。但没有什么可以单击...
OK. If singleFingerTap.numberOfTapsRequired = 2;
then all works fine as well. But nothing for single tap..
推荐答案
实际上,答案很简单:
- 将自己设置为UIGestureRecognizer委托
- 为委托方法返回YES:
例如
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)];
tapGestureRecognizer.delegate = self;
以及代码中的其他地方:
and somewhere else in the code:
#pragma mark - gesture delegate
// this allows you to dispatch touches
- (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 {
return YES;
}
这篇关于MPMoviePlayerController的视图无法识别触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!