3

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?

GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
Kabir Shah
  • 179
  • 1
  • 2
  • 12

2 Answers2

2

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.view.addGestureRecognizer(swipeGesture)
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
  }
}
Ajith Renjala
  • 4,934
  • 5
  • 34
  • 42
0

Swiping Up & Down are the default property of table view. I would suggest you to disable the scrolling of the table view whenever you want to do something on the overlay.

tableView.scrollEnabled = NO;

If you are performing dragging of a particular cell then long press on it and then start dragging.

This is how you can achieve this.

Hope this helps.

Jobins John
  • 1,265
  • 23
  • 45