Questions tagged [uigesturerecognizer]

UIGestureRecognizer is an abstract base class for concrete gesture-recognizer classes. A gesture-recognizer object (or, simply, a gesture recognizer) decouples the logic for recognizing a gesture and acting on that recognition. When one of these objects recognizes a common gesture or, in some cases, a change in the gesture, it sends an action message to each designated target object.

The UIGestureRecognizer class defines a set of common behaviors that can be configured for all concrete gesture recognizers. It can also communicate with its delegate (an object that adopts the UIGestureRecognizerDelegate protocol), thereby enabling finer-grained customization of some behaviors.

A gesture recognizer operates on touches hit-tested to a specific view and all of that view’s subviews. It thus must be associated with that view. To make that association you must call the UIView method addGestureRecognizer:. A gesture recognizer does not participate in the view’s responder chain.

A gesture recognizer has one or more target-action pairs associated with it. If there are multiple target-action pairs, they are discrete, and not cumulative. Recognition of a gesture results in the dispatch of an action message to a target for each of those pairs. The action methods invoked must conform to one of the following signatures:

 - (void)handleGesture;
 - (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer;

Resources:

3632 questions
386
votes
7 answers

UILongPressGestureRecognizer gets called twice when pressing down

I am detecting if the user has pressed down for 2 seconds: UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self …
346
votes
18 answers

How to disable back swipe gesture in UINavigationController on iOS 7

In iOS 7 Apple added a new default navigation behavior. You can swipe from the left edge of the screen to go back on the navigation stack. But in my app, this behavior conflicts with my custom left menu. So, is it possible to disable this new…
ArtFeel
  • 11,701
  • 4
  • 29
  • 41
256
votes
13 answers

Can you attach a UIGestureRecognizer to multiple views?

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTapTap:)]; [self.view1 addGestureRecognizer:tapGesture]; [self.view2 addGestureRecognizer:tapGesture]; [tapGesture release]; In the above…
kubi
  • 48,104
  • 19
  • 94
  • 118
224
votes
24 answers

How to call gesture tap on UIView programmatically in swift

I have a UIView and and I have added tap gesture to it: let tap = UITapGestureRecognizer(target: self, action: Selector("handleTap:")) tap.delegate = self myView.addGesture(tap) I am trying to call it programmatically in the…
George
  • 3,600
  • 2
  • 26
  • 36
186
votes
8 answers

UIGestureRecognizer on UIImageView

I have a UIImageView, which I want to be able to resize and rotate etc. Can a UIGestureRecognizer be added to the UIImageView? I would want to add a rotate and pinch recognizer to a UIImageView which would be created at runtime. How does one add…
some_id
  • 29,466
  • 62
  • 182
  • 304
169
votes
9 answers

UITapGestureRecognizer - single tap and double tap

I am trying to add 2 UITapGestureRecognizers to a view, one for single tap and one for double tap events. The single tap recognizer is working as expected (on its own). But I don't seem to be able to get the double tap recognizer working. Have…
Stanley
  • 4,446
  • 7
  • 30
  • 48
157
votes
22 answers

UIPanGestureRecognizer - Only vertical or horizontal

I have a view that has a UIPanGestureRecognizer to drag the view vertically. So in the recognizer callback, I only update the y-coordinate to move it. The superview of this view, has a UIPanGestureRecognizer that will drag the view horizontally,…
LocoMike
  • 5,626
  • 5
  • 30
  • 43
148
votes
25 answers

How do I Disable the swipe gesture of UIPageViewController?

In my case parent UIViewController contains UIPageViewController which contains UINavigationController which contains UIViewController. I need to add a swipe gesture to the last view controller, but swipes are handled as if they belong to page view…
122
votes
16 answers

Disable gesture to pull down form/page sheet modal presentation

In iOS 13 modal presentations using the form and page sheet style can be dismissed with a pan down gesture. This is problematic in one of my form sheets because the user draws into this box which interferes with the gesture. It pulls the screen down…
Jordan H
  • 52,571
  • 37
  • 201
  • 351
101
votes
9 answers

Gesture recognizer and button actions

I have a view hierarchy that looks something like this: UIView (A) UIView > UIImageView UIView > UIView (B) UIView > UIView (B) > Rounded Rect Button UIView > UIView (B) > UIImageView UIView > UIView (B) > UILabel I've attached gesture…
Mustafa
  • 20,504
  • 42
  • 146
  • 209
99
votes
19 answers

No Swipe Back when hiding Navigation Bar in UINavigationController

I love the swipe pack thats inherited from embedding your views in a UINavigationController. Unfortunately i cannot seem to find a way to hide the NavigationBar but still have the touch pan swipe back gesture. I can write custom gestures but I…
mihai
  • 4,184
  • 3
  • 26
  • 27
84
votes
10 answers

UIGestureRecognizer blocks subview for handling touch events

I'm trying to figure out how this is done the right way. I've tried to depict the situation: I'm adding a UITableView as a subview of a UIView. The UIView responds to a tap- and pinchGestureRecognizer, but when doing so, the tableview stops…
andershqst
  • 1,454
  • 1
  • 14
  • 24
73
votes
7 answers

How can I tell a UIGestureRecognizer to cancel an existing touch?

I have a UIPanGestureRecognizer I am using to track an object (UIImageView) below a user's finger. I only care about motion on the X axis, and if the touch strays above or below the object's frame on the Y axis I want to end the touch. I've got…
Josh French
  • 973
  • 1
  • 6
  • 12
68
votes
3 answers

How to remove all gesture recognizers from a UIView in Swift

I have written Swift code that attempts to remove all gesture recognizers from all subviews of a given custom UIView type. let mySubviews = self.subviews.filter() { $0.isKindOfClass(CustomSubview) } for subview in mySubviews { for recognizer…
Brian McCafferty
  • 683
  • 1
  • 5
  • 6
63
votes
3 answers

How can I capture which direction is being panned using UIPanGestureRecognizer?

Ok so I have been looking around at just about every option under the sun for capturing multi-touch gestures, and I have finally come full circle and am back at the UIPanGestureRecognizer. The functionality I want is really quite simple. I have…
Brandon B.
  • 727
  • 2
  • 8
  • 9
1
2 3
99 100