0

I've written a code and did an IB action from the main storyboard to the view controller for a swipe gesture action.

@IBAction func swipeToSwitchScheme(_ sender: UISwipeGestureRecognizer) {
        if sender.direction == .right{
            switchCurrentScheme()
        }

        else if sender.direction == .left {
            print("swiped left")
        }
    }

However, it seems like it can only detect .right gesture and not left. Is there something wrong with how I execute the gestureRecogniser?

Thanks!

Edit:

@IBAction func swipeToSwitchScheme(_ sender: UISwipeGestureRecognizer) {
        if sender.direction == .right {
            switchCurrentScheme()
        }
    }
    @IBAction func swipeLeft(_ sender: UISwipeGestureRecognizer) {
        if sender.direction == .left {
            print("swipe left")
            switchCurrentSchemeLeft()
        }
    }

I got it like this but only the right gesture is recognised

lws803
  • 907
  • 2
  • 10
  • 21
  • Show the code where you have added `GestureRecognizer` to view. – Nirav D Oct 24 '16 at 05:25
  • Oh I did it in storyboard, I didnt do it programmatically – lws803 Oct 24 '16 at 05:26
  • 3
    According to http://stackoverflow.com/a/7760927/1187415, you need separate swipe gesture recognizers for each direction. – Martin R Oct 24 '16 at 05:27
  • Oh, I've tried that before. But in doing so it cancels each other out. Both recognisers are not working or printing anything. – lws803 Oct 24 '16 at 05:31
  • Thats impossible. They cannot be recognized at the same moment. – Sulthan Oct 24 '16 at 06:58
  • Hmm still not working for me. Could it be that I have other interactive objects in the view as well like buttons and such. – lws803 Oct 24 '16 at 07:35
  • @Wilson add two gestures from storyboard as mentioned in third answer in [this](http://stackoverflow.com/questions/24215117/how-to-recognize-swipe-in-all-4-directions) thread – Umair Afzal Oct 24 '16 at 07:50

1 Answers1

0

I found the solution, apparently if you wanna add two gesture recognisers in the same view, you'll have to define both of their directions in viewDidLoad. So put both of the recogniser's outlets to the swift file and then set them to their respective directions in viewDidLoad.

lws803
  • 907
  • 2
  • 10
  • 21