Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a segue to an UIGestureRecognizer

I am building an app for the first time using Storyboards. I have a scene which I would like to have open another scene when there is a long tap on a particular button. I am able to add the UILongPressGestureRecognizer with no problem, but I can't figure out how to have that gesture be the segue to the other scene. Doesn't seem to matter what I Ctrl-Drag, nothing works.

Am I missing something obvious?

Thanks, Ken

like image 928
macgeezer Avatar asked Aug 09 '12 17:08

macgeezer


People also ask

How do I add segue to iOS?

To create a segue from the controller Control-drag from the View Controller icon to the Exit icon. Give this new segue the identifier unwind to reference it from the code.

How do you add gestures to a storyboard?

Adding a Tap Gesture Recognizer in Interface Builder You don't need to switch between the code editor and Interface Builder. Open Main. storyboard and drag a tap gesture recognizer from the Object Library and drop it onto the view we added earlier. The tap gesture recognizer appears in the Document Outline on the left.

What is UITapGestureRecognizer Swift?

UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer . For gesture recognition, the specified number of fingers must tap the view a specified number of times. Although taps are discrete gestures, they're discrete for each state of the gesture recognizer.


2 Answers

You can control-drag from your first controller's window to your second controller to create the segue, and then you can call performSegueWithIdentifier in your GestureRecognizer method.

like image 56
danqing Avatar answered Oct 05 '22 04:10

danqing


It's now possible to do it all in your Storyboard visually. Every gesture recognizer has Triggered Segues in Connections Inspector.

like image 37
Rudolf Adamkovič Avatar answered Oct 05 '22 04:10

Rudolf Adamkovič