gpt4 book ai didi

ios - MPMoviePlayerController 无法识别 UITapGestureRecognizer

转载 作者:行者123 更新时间:2023-11-29 02:16:22 27 4
gpt4 key购买 nike

我正在尝试将 UITapGestureRecognizer 添加到我的 MPMoviePlayerController,如下所示:

- (void)playVideo {
NSString *videoURL = self.post[@"videos"][@"high_resolution"];
videoURL = [videoURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:videoURL];
self.videoURL = url;

self.videoController = [[MPMoviePlayerController alloc] init];
self.videoController.controlStyle = MPMovieControlStyleNone;
self.videoController.backgroundView.backgroundColor = [UIColor clearColor];

[self.videoController setContentURL:self.videoURL];
[self.videoController.view setFrame:CGRectMake (0, 0, 320, 320)];
[_sharedImage addSubview:self.videoController.view];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playy)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.videoController];
self.playBtn.hidden = YES;
[self.videoController play];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[_videoController.view addGestureRecognizer:tap];

}

- (void)handleTap:(UITapGestureRecognizer *)gesture {
[_videoController pause];
NSLog(@"Video was tapped");
}

#pragma mark - Gesture Delegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

但是 MPMoviePlayerController 似乎无法识别点击手势,并且当我点击视频时没有任何反应。请解释一下。谢谢!

最佳答案

你应该像这样设置禁用交互......

self.videoController.userInteractionEnabled = false;

然后将您的手势添加到父 View

[self.view addGestureRecognizer:tap];

关于ios - MPMoviePlayerController 无法识别 UITapGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28707689/

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