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 に答える