【发布时间】:2013-03-02 20:26:45
【问题描述】:
我正在尝试使用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;
【问题讨论】:
-
当以你的方式使用全屏时,`MPMoviePlayerController 并没有真正使用它的正常视图,而是直接在窗口上播放。为了让您的代码也能在全屏模式下运行,一旦玩家切换到全屏模式,您就必须添加该手势识别器。您可能希望在窗口的视图堆栈中找到 MPMovieView 的实例并将其添加到该视图中。
标签: ios objective-c mpmovieplayercontroller uitapgesturerecognizer