0

当我点击我的MPMoviePlayerController时,没有任何反应。任何人都可以看到我在设置UITapGestureRecognizer时做错了什么?向MPMoviePlayerController添加UITapGestureRecognizer

- (void) playMovie : (NSString *) urlString{ 

    self.movieURLString = urlString; 

    NSURL *movieURL = [NSURL URLWithString:self.movieURLString]; 

    self.moviePlayer = [[MPMoviePlayerController alloc] init]; 
    [self.moviePlayer setShouldAutoplay:YES]; 
    [self.moviePlayer setContentURL:movieURL.absoluteURL]; 
    [self.moviePlayer setMovieSourceType:MPMovieSourceTypeFile]; 
    self.moviePlayer.controlStyle = MPMovieControlStyleNone; 

    self.moviePlayer.view.frame = self.movieView.frame; 

    /* add tap handler */ 
    UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showControls:)]; 
    singleFingerTap.delegate = self; 

    //EDIT: this line somehow didn't make into my OP 
    [self.moviePlayer.view addGestureRecognizer:singleFingerTap]; 

    self.moviePlayer.view.backgroundColor = [UIColor clearColor]; 
    [self.view addSubview:self.moviePlayer.view]; 
    [self.moviePlayer prepareToPlay]; 

    // respond to changes in movie player status 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(myMovieFinishedCallback:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:self.moviePlayer]; 

} 

- (void) showControls : (UITapGestureRecognizer *) recognizer { 
    NSLog(@"here"); 
    self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded; 

} 
+0

我没有检查你的文章的细节,但我想你错过了'MPMoviePlayerController'本身使用几个手势识别器的事实,你的永远不会因为冲突而被触发。 – Till 2014-09-20 20:37:51

回答

0

您从未将手势识别器添加到视图中,这就是错误。

[self.moviePlayer.view addGestureRecognizer:singleFingerTap]; 

但也没有必要设置委托,除非你要实现一些在UIGestureRecognizerDelegate协议的方法。

+0

不知何故,这并没有使它成为我发布的代码。我试过这个,但仍然没有回应。我不明白。谢谢! – Alex 2014-09-20 02:20:18

相关问题