简体   繁体   English

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

[英]MpMovieplayerController tap gesture recognizer doesn't trigger when in fullscreen

I´m trying to use UITapGestureRecognizer in order to handle the taps on my fullscreen video. 我正在尝试使用UITapGestureRecognizer来处理全屏视频上的点击。 If I omit [self.player setFullscreen:YES animated:NO]; 如果我省略[self.player setFullscreen:YES animated:NO]; it works, but then my video won't scale to fit the screen. 它工作,但然后我的视频将无法缩放以适应屏幕。

From my .m: 从我的.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");
}

From my .h: 从我的.h:

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

You can try this: 你可以试试这个:

[[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];
}

and then remove your subview when MPMoviePlayerWillExitFullscreenNotification is posted 然后在发布MPMoviePlayerWillExitFullscreenNotification时删除子视图

In my comment, I drafted how to get that covered when using proper fullscreen ( [self.player setFullscreen:YES animated:NO]; ). 在我的评论中,我选择了如何在使用适当的全屏时( [self.player setFullscreen:YES animated:NO]; )进行覆盖。

I would suggest that instead you simply resize the player view to cover the entire screen by setting its frame accordingly. 我建议您只需调整播放器视图的大小,通过相应地设置其框架来覆盖整个屏幕。

You initialising code would have to get rid of that player.fullscreen = YES; 你初始化代码必须摆脱那个player.fullscreen = YES; , but that I guess is obvious by now. ,但我想现在很明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM