thefan12345
thefan12345

Reputation: 136

Simple Swipe in Swift - xCode 6

I'm trying to make a simple swipe up gesture, I dragged the Swipe Gesture Recogniser over a UIImage, I then Ctrl button drag the Swipe Gesture to my swift file and create the following Action: -

@IBAction func swipeDice(sender: UISwipeGestureRecognizer) {
    //Test display
    testLabel.text = "Zing"
}

The app builds and runs successfully however when I test the swipe gesture it doesn't seem to do anything.

Is that all the code I need for the gesture to run? How do I make it recognise a 2 finger swipe gesture?

Upvotes: 1

Views: 1602

Answers (3)

vacawama
vacawama

Reputation: 154721

You need to enable User Interaction for the UIImage that you added the UIGestureRecognier to:

Open the Attributes Inspector for the UIImage and tick User Interaction Enabled:

Enabling User Interaction on a UIImage

Upvotes: 2

Francescu
Francescu

Reputation: 17054

If you created the Swipe Gesture Recognizer in IB you can setup the gesture through the right window.

enter image description here

If you have a conflict between several gestures you can handle this through the UIGestureRecognizerDelegate protocol.

Upvotes: 1

zisoft
zisoft

Reputation: 23078

Add the following function to your code:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
}

Upvotes: 0

Related Questions