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

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

本文介绍了MpMovieplayerController轻触手势识别器在全屏时不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I´m trying to use UITapGestureRecognizer in order to handle the taps on my fullscreen video. If I omit [self.player setFullscreen:YES animated:NO]; it works, but then my video won't scale to fit the screen.

来自我的.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]; )。

In my comment, I drafted how to get that covered when using proper fullscreen ([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.

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

You initialising code would have to get rid of that player.fullscreen = YES;, but that I guess is obvious by now.

这篇关于MpMovieplayerController轻触手势识别器在全屏时不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:20