Mercutio
Mercutio

Reputation: 1296

Problems swiping right with UISwipeGestureRecognizer (Swift 3.0)

After watching this quick demo, I set up very similar swipeLeft and swipeRight methods. I've ensured that the two gesture recognizers I added to the scene were set to "left" and "right" respectively, and verified that my @IBActions were linked to the correct recognizers.

For some reason, the swipe left recognizer is working but the swipe right isn't (which is even more strange, since most of what I'm reading discusses how the recognizer directions are default right). I've tested this on an iPhone 8 and the simulator (SE + 10).

When I'm using the terms "left" and "right" I'm assuming they mean the direction the swipe is headed (e.g. left = starting from right side and sliding finger to the left).

My methods are as follows:

@IBAction func swipeLeft(_ sender: UISwipeGestureRecognizer) {
    print("swiped left")
}

@IBAction func swipeRight(_ sender: UISwipeGestureRecognizer) {
    print("swipe right")
}

(R) is the one not working...

UPDATE

Both bubbles to the left of the IBActions (used to connect to the view controller) are filled in. When I click them (tried to get a screenshot, but it goes away) they both show that they're connected (respectively):

Main.storyboard -- Swipe Gesture Recognizer (R)
Main.storyboard -- Swipe Gesture Recognizer (L)

However, when I right click the recognizers, there's a disparity on their connections. They both show sent actions for their respective methods, but the (L) has a Referencing Outlet Collections while (R) doesn't.

After connecting that up, everything is working. Not sure why it didn't connect originally, but that solved it. Thanks for everyones' help.

Upvotes: 0

Views: 524

Answers (1)

Yitzchak
Yitzchak

Reputation: 3416

I don't know if you dragged it on the view that should listen to the gesture. Check the links pane to see differences between them and link between the right gesture to the view Maybe the first gesture recognizer disables the second, try to disable the first and see if it helps.. You should set them to forward touches to other recognizers

EDIT: as you said, you should've add a connection to referencing outlets Glad I could help you (I had this problem at the past) good luck!

Upvotes: 1

Related Questions