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

相關問題