gpt4 book ai didi

ios - MpMovieplayerController 点击手势识别器在全屏时不会触发

转载 作者:可可西里 更新时间:2023-11-01 05:45:37 26 4
gpt4 key购买 nike

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

来 self 的.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");
}

来 self 的.h:

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

最佳答案

你可以试试这个:

[[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 时删除您的 subview

关于ios - MpMovieplayerController 点击手势识别器在全屏时不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15179095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com