2017-02-25 51 views
0

我在我的collectionView單元格中顯示三個視圖。一個在中間完成,在contentView的角落預覽next和previous。並使用panGesture刷中間視圖。我如何禁用側視圖panGesture?禁用contentView中sideViews的手勢

這裏是圖像:enter image description here

我已經加入panGestureRecognizer上的內容圖。但我不想從側面看這個姿勢,還想讓側面的圖像顏色變得很暗淡。我該怎麼做?

回答

0

您可以使用UIGestureRecognizerDelegate。實現方法:

func wasDragged(gestureRecognizer: UIPanGestureRecognizer) { 

    if gestureRecognizer.state == UIGestureRecognizerState.began { 
     print("was dragged began") 
    } 
    if gestureRecognizer.state == UIGestureRecognizerState.changed { 
     print("was dragged change \(gestureRecognizer.location(in: self.view))") 
     testTouches(touches: gestureRecognizer.location(in: self.view)) 
    } 
    if gestureRecognizer.state == UIGestureRecognizerState.ended { 
     print("was dragged ended") 
    } 
} 

不是執行的方法來測試觸摸點:

func testTouches(touches: CGPoint) { 
    // Get location of touch 

    let touchLocation = touches 
    // Convert the location of the side views to this view controller's view coordinate system 
    let sideViewFrame = self.view.convert(sideView.frame, from: sideView.superview)// Check if touch is inside side view 
    if sideViewFrame.contains(touchLocation) { 
      // do nothing 
     } 
     else { 
      // do something 
     } 
}