Tutorial by Examples

Initialize the UITapGestureRecognizer with a target, self in this case, and an action which is a method that has a single parameter: a UITapGestureRecognizer. After initialization, add it to the view that it should recognize taps in. Swift override func viewDidLoad() { super.viewDidLoad() ...
Pan gesture recognizers detect dragging gestures. The following example adds an image to a view controller and lets the user drag it around on screen. Objective-C - (void)viewDidLoad { [super viewDidLoad]; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNa...
The double tap, like a single tap, also uses the UITapGestureRecognizer. You simply set the numberOfTapsRequired to 2. Swift override func viewDidLoad() { super.viewDidLoad() // Double Tap let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleDoubleTa...
The UILongPressGestureRecognizer lets you listen for a long press on a view. You can set the length of delay before the action method is called. Swift override func viewDidLoad() { super.viewDidLoad() // Long Press let longPressGesture = UILongPressGestureRecognizer(target: self, ...
Swipe gestures allow you to listen for the user moving their finger across the screen quickly in a certain direction. Swift override func viewDidLoad() { super.viewDidLoad() // Swipe (right and left) let swipeRightGesture = UISwipeGestureRecognizer(target: self, action: #selector(...
Pinches are a two fingered gesture where the fingers move closer or farther from each other. This gesture is generally used for resizing a view. Swift override func viewDidLoad() { super.viewDidLoad() // Pinch let pinchGesture = UIPinchGestureRecognizer(target: self, action: #sele...
Two fingers rotating around a center can be listened for with the UIRotationGestureRecognizer. This is generally used for rotating a view. Swift override func viewDidLoad() { super.viewDidLoad() // Rotate let rotateGesture = UIRotationGestureRecognizer(target: self, action: #selec...
Drag a gesture recognizer from the object library onto your view. Control drag from the gesture in the Document Outline to your View Controller code in order to make an Outlet and an Action. Notes This example comes from this fuller sample project demonstrating gesture recognizers.

Page 1 of 1