MpMovieplayerController轻触手势识别器在全屏时不会触发

我正在尝试使用UITapGestureRecognizer来处理全屏video上的点击。 如果我省略[self.player setFullscreen:YES animated:NO]; 它工作,但然后我的video将无法缩放以适应屏幕。

从我的.m:

 - (void)viewDidLoad { [super viewDidLoad]; NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mov"]; player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]]; player.shouldAutoplay = NO; player.view.frame = self.view.bounds; player.scalingMode = MPMovieScalingModeAspectFit; player.controlStyle = MPMovieControlStyleNone; player.fullscreen = YES; self.player = player; [self.player prepareToPlay]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; UIView *aView = [[UIView alloc] initWithFrame:player.view.bounds]; [aView addGestureRecognizer:tapGesture]; [self.player.view addSubview:aView]; } - (IBAction)playMovie:(id)sender { //add the MPMoviePlayerViewController to this view (as subview) //Play movie [self.view addSubview:self.player.view]; [self.player setFullscreen:YES animated:NO]; //commenting out this will make it work [self.player play]; } - (void)handleTap:(UITapGestureRecognizer *)recognizer { NSLog(@"tap tap"); } 

从我的.h:

 @property (retain, nonatomic) MPMoviePlayerController *player; - (void)handleTap:(UITapGestureRecognizer *)recognizer; 

在我的评论中,我起草了如何在使用正确的全屏时( [self.player setFullscreen:YES animated:NO]; )完成覆盖。

我建议您只需调整播放器视图的大小,通过相应地设置其框架来覆盖整个屏幕。

你初始化代码必须摆脱那个player.fullscreen = YES; ,但我想现在很明显。

你可以试试这个:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil]; - (void)willEnterFullScreen:(NSNotification*)notification { UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; UIView *aView = [[UIView alloc] initWithFrame:self.player.backgroundView.bounds]; [aView addGestureRecognizer:tapGesture]; [self.view.window addSubview:aView]; } 

然后在发布MPMoviePlayerWillExitFullscreenNotification时删除子视图