4

我正在尝试使用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;
4

2 回答 2

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

于 2013-03-02T21:14:34.317 回答
1

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

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

您初始化代码将不得不摆脱它player.fullscreen = YES;,但我想现在很明显。

于 2013-03-02T20:52:01.390 回答