K. Shah K. Shah - 3 months ago 31
Swift Question

UITableView can be dragged up and down, not allowing Swipe Gesture?

I am a beginner in Swift, and am trying to add a swipe gesture recognizer to my UIView. I have inserted a gradient CALayer to index 0 to have a gradient background.

My problem is:

Swipe gestures for right and left work fine, but for Down it doesn't work, why?


Set the delegate of swipe gestures that you are adding to the view.

let swipeGesture = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipe:"))
swipeGesture.delegate = self
self.mySwipeGesture = swipeGesture

GestureRecognizerDelegate asks if two gesture recognizers should be allowed to recognize gestures simultaneously. Return true to allow both gestureRecognizer and otherGestureRecognizer to recognize their gestures simultaneously. The default implementation returns false—no two gestures can be recognized simultaneously. Implement the following delegate to achieve this.

extension ViewController : UIGestureRecognizerDelegate {
  func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    //Identify gesture recognizer and return true else false.
    return gestureRecognizer.isEqual(self.mySwipeGesture) ? true : false