3
votes

If I create an single-view application with XCODE 5, I can detect tap gestures on the MPMoviePlayerController during a full-screen movie playback without problems.

However, if I embed the main ViewController in a Navigation Controller, I can no longer detect taps during the full-screen movie playback.

I reason I'm using the Navigation Controller is mainly because I need to switch from full-screen video playback to a full-screen camera preview when the user taps the screen, and when the user taps again, it should go back from the camera preview to the video playback.

I've tried different approaches but I can't seem to detect the screen tap during movie playback when a Navigation Controller is present.

Any hints on how to achieve this?

Thanks.

3
If you solve your problem accept the answerMirko Catalano

3 Answers

3
votes

for do that you have to make a SubCLass of MPMoviePlayerController and then you implement the

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

Or

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

depend if you what do that when the use touch up or down

2
votes

Working code for me:

{
    /* create player and add to parent view */
    ...

    /* add tap handler */
    UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onPlayerTapped:)];
    singleFingerTap.numberOfTapsRequired = 1;
    singleFingerTap.delegate = self;
    [moviePlayer.view addGestureRecognizer:singleFingerTap];
}

-(void) onPlayerTapped:(UIGestureRecognizer *)gestureRecognizer {
    isInPlayingMode = NO;
}

#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;
}

REFERENCE: MPMoviePlayerController's view does not recognize touch

0
votes

You need to remember to add the following without them it won't work as MPMoviePlayerController is a custom subclass not a view controller

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    return true;

}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return true;

}

And also don't forget to declare the UIGestureRecognizer delegate as self