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

时间:2013-03-02 20:26:46

标签: ios objective-c mpmovieplayercontroller uitapgesturerecognizer

我正在尝试使用UITapGestureRecognizer来处理全屏视频上的点按。如果我省略[self.player setFullscreen:YES animated:NO];它可以正常工作,那么我的视频将无法缩放以适应屏幕。

从我的.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;

2 个答案:

答案 0 :(得分:2)

你可以试试这个:

[[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时删除您的子视图

答案 1 :(得分:1)

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

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

您初始化代码必须摆脱player.fullscreen = YES;,但我想这是显而易见的。

相关问题