How to detect touch on MPMoviePlayerViewController
I instantiated MPMoviePlayerViewController and load movie with it. How can I detect when user touch anywhere on the player then?
I added overlay and it works like that. But problem is that now I don't have controls on player (volume, pau开发者_如何学Gose etc.). Is there any notification to display this?
you might add the gesture recognizer to the view that is the parent of the movie player.
then you could add a delegate to the gesture recognizer to check what exactly was hit ... and discard the gesture recognizer event in case that it was not the media player.
the code could look like:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
UIView *treffer = [app.window hitTest:[touch locationInView:app.window] withEvent:nil];
if (treffer == yourvideoplayerview) return YES;
return NO;
}
Another easy option is to put a big invisible button over the movie player view.
You might have two recognisers fighting. You can add a recogniser from you parent controller, conform to <UIGestureRecogniserDelegate>
, set yourself as the gesture recogniser's delegate and implement:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
So they can all play along happily.
精彩评论