2012-03-04 125 views
2

我有一個UIScrollView,我需要能夠滾動。同時,我需要檢測滾動視圖上的點擊。我怎樣才能做到這一點?UIScrollView檢測水龍頭

我已經嘗試添加一個TapGestureRecognizer視圖沒有任何運氣。還嘗試了使用UIScrollViewDelegate方法的幾種方法。

UIScrollView中有MPMoviePlayerController視圖。

我用下面的代碼添加reconigzer

UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)] autorelease]; 
singleTap.enabled = YES; 
singleTap.cancelsTouchesInView = NO; 

[scrollView addGestureRecognizer:singleTap]; 

感謝。

回答

0

解決方案:將MPMoviePlayerController視圖添加到UIScrollView時,需要禁用MpMoviePlayerController視圖上的用戶交互,以便UIScrollView能夠捕獲手勢識別器。此解決方案ofc僅適用於不希望使用mpmovieplayercontrollers默認菜單等進行交互時。

1

嘗試在滾動視圖中添加視圖並添加手勢識別器和其他視圖。

+0

你的反應是不是正確的解決方案,但是,它導致我來吧。當我在scrollview中添加mp-view時,我必須禁用mpmovieplayercontroller上的userinteraction以處理該手勢。 – Kenneth 2012-03-04 19:38:11

+0

然後讓您的解決方案成爲答案並接受它作爲正確的答案。 – dasdom 2012-03-05 07:41:33

0

您可以在UIScrollView中捕獲任何類型的手勢。確保你也處理一些默認屬性,就像設置cancelsTouchesInView屬性爲false,默認情況下是true。還給你的子視圖標記號以區分選擇器。 &也使他們的用戶交互爲真。

例如。我加入我的滾動視圖的形象圖,我實現了用戶交互以及我也更新其內容的大小,

{ 
      //adding images to the scroll view 
      for i in 0 ..< 4 { 
      let image = UIImage(named: "img\(i).png") 
      let imageView = UIImageView(image: image) 
      imageView.center = CGPoint(x: CGFloat(i) * 60 + 60/2, y: 60/2) 
      imageView.tag = i 
      imageView.isUserInteractionEnabled = true 
      addSubview(imageView) 

      let tap = UITapGestureRecognizer(target: self, action: #selector(didTapImage(_:))) 
      imageView.addGestureRecognizer(tap) 
     } 

     contentSize = CGSize(width: 10 * 60, height: 60 + 2*10) 

}