Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController's view does not recognize touch

Tags:

This is my code:

_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 works fine. In addition I want to handle touch on MPMoviePlayerController view but handleRollTap never called. Why MPMoviePlayerController's view not works with UITapGestureRecognizer?


OK. If singleFingerTap.numberOfTapsRequired = 2; then all works fine as well. But nothing for single tap..


like image 695
beryllium Avatar asked Sep 20 '11 14:09

beryllium


1 Answers

Actually, answer to this is simple:

  • set yourself as UIGestureRecognizer delegate
  • return YES for delegate methods:

e.g.

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; } 
like image 146
mdomans Avatar answered Oct 18 '22 18:10

mdomans