3

如果我使用 XCODE 5 创建单视图应用程序,我可以在全屏电影播放期间检测 MPMoviePlayerController 上的轻击手势而不会出现问题。

但是,如果我将主 ViewController 嵌入到导航控制器中,我将无法在全屏电影播放期间检测到点击。

我之所以使用导航控制器主要是因为当用户点击屏幕时我需要从全屏视频播放切换到全屏相机预览,当用户再次点击时,它应该从相机返回预览到视频播放。

我尝试了不同的方法,但是当存在导航控制器时,我似乎无法在电影播放期间检测到屏幕点击。

关于如何实现这一目标的任何提示?

谢谢。

4

3 回答 3

3

为此,您必须创建一个 SubCLass ,MPMoviePlayerController然后实现

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

或者

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

取决于你在向上或向下使用时会做什么

于 2013-11-06T01:08:02.137 回答
2

为我工作的代码:

{
    /* create player and add to parent view */
    ...

    /* add tap handler */
    UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onPlayerTapped:)];
    singleFingerTap.numberOfTapsRequired = 1;
    singleFingerTap.delegate = self;
    [moviePlayer.view addGestureRecognizer:singleFingerTap];
}

-(void) onPlayerTapped:(UIGestureRecognizer *)gestureRecognizer {
    isInPlayingMode = NO;
}

#pragma mark - gesture delegate
// this allows you to dispatch touches
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    return YES;
}
// this enables you to handle multiple recognizers on single view
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

参考:MPMoviePlayerController 的视图无法识别触摸

于 2013-11-16T19:56:04.307 回答
0

您需要记住在没有它们的情况下添加以下内容,因为 MPMoviePlayerController 是自定义子类而不是视图控制器

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    return true;

}

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

}

并且不要忘记将UIGestureRecognizer 委托声明为self

于 2015-04-09T02:06:59.467 回答