使用故事板和导航控制器检测MPMoviePlayerController上的点击

时间:2013-11-06 00:56:07

标签: ios objective-c uinavigationcontroller storyboard mpmovieplayercontroller

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

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

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

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

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

感谢。

3 个答案:

答案 0 :(得分:3)

要做到这一点,你必须制作MPMoviePlayerController的SubCLass,然后实施

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

或者

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

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

答案 1 :(得分: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's view does not recognize touch

答案 2 :(得分:0)

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

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

}

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

}

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