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
28
votes
9 answers

How To select a table row during a long press in Swift

I have a table which has a long press gesture recogniser that runs code depending on what table row is selected. The trouble I'm having is that I currently have to tap the row I want then do the long press. How can I make the table select the row…
LB79
  • 1,285
  • 2
  • 12
  • 20
27
votes
7 answers

Detect when UIGestureRecognizer is up, down, left and right Cocos2d

I have a CCSprite that I want to move around using gestures. Problem is I'm completely new to Cocos2D. I want my sprite to perform one action when the gesture is up, another one when gesture is down, another action when gesture is right and same…
Magnus
  • 1,444
  • 5
  • 22
  • 31
27
votes
8 answers

How do I capture the point initially tapped in a UIPanGestureRecognizer?

I have an app that lets the user trace lines on the screen. I am doing so by recording the points within a UIPanGestureRecognizer: -(void)handlePanFrom:(UIPanGestureRecognizer *)recognizer { CGPoint pixelPos = [recognizer…
todd412
  • 1,308
  • 2
  • 17
  • 24
26
votes
8 answers

How to recognize swipe in all 4 directions?

I need to recognize swipes in all directions (Up/Down/Left/Right). Not simultaneously, but I need to recognize them. I tried: UISwipeGestureRecognizer *Swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self…
elp
  • 8,021
  • 7
  • 61
  • 120
26
votes
4 answers

Is it possible to programmatically show the red delete button on a UITableViewCell?

There are lots of similar questions on here, but none that I think specifically ask this question, which is, is there any way in code to force the red delete button to appear at the right-side of a UITableView row? The reason I ask is that I'm…
glenc
  • 3,132
  • 2
  • 26
  • 42
26
votes
4 answers

How to have a UISwipeGestureRecognizer AND UIPanGestureRecognizer work on the same view

How would you setup the gesture recognizers so that you could have a UISwipeGestureRecognizer and a UIPanGestureRecognizer work at the same time? Such that if you touch and move quickly (quick swipe) it detects the gesture as a swipe but if you…
Shizam
  • 9,627
  • 8
  • 51
  • 82
26
votes
3 answers

Gesture problem: UISwipeGestureRecognizer + UISlider

Got a gesture related problem. I implemented UISwipeGestureRecognizer to get swipe left and right events and that is working fine. However the problem I'm facing is that the UISlider's I have in the same view are not playing nice. The sliding motion…
26
votes
3 answers

How to add tap gesture to UICollectionView , while maintaining cell selection?

Task Add a single tap gesture to UICollectionView, do not get in the way of cell selection. I want some other taps on the no-cell part of the collectionView. Code Using XCode8, Swift 3. override func viewDidLoad() { ... …
addlistener
  • 871
  • 1
  • 12
  • 20
26
votes
5 answers

Simultaneous gesture recognizers in Iphone SDK

I need to catch two different swipping gestures using UISwipeGestureRecognizer(for example, UISwipeGestureRecognizerDirectionRight and UISwipeGestureRecognizerDirectionLeft). When I add two different recognisers with addGestureRecognizer method,…
user294890
  • 633
  • 1
  • 6
  • 8
26
votes
5 answers

Allow UIScrollView and its subviews to both respond to a touch

I want both my UIScrollView and its subviews to receive all touch events inside the subview. Each can respond in its own way. Alternatively, if tap gestures were forwarded to subviews, all would be well. A lot of people are struggling in this…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
25
votes
6 answers

interactivePopGestureRecognizer corrupts navigation stack on root view controller

In my UINavigationController I added custom back buttons with the side effect that it is not possible anymore to swipe left to right to pop the view controller and navigate back. So I implemented interactivePopGestureRecognizer in my custom…
Manuel
  • 14,274
  • 6
  • 57
  • 130
25
votes
4 answers

Problems with gesture recognizer in iOS 7

I'm adding several UIView objects (e.g. 5) to the screen, one inside the other. This, for example, view5.superview = view4, view4.superview = view3, view3.superview=view2, view2.superview = view1. For all these UIView I set uitapgesturerecognizer;…
Kup
  • 301
  • 1
  • 3
  • 9
25
votes
5 answers

Tap Recognition for UIImageView in the UITableViewCell

Currently I'm facing a problem, I would like to perform action when the UIImageView on my UITableViewCell had been tapped. Question: How could I do it? Could any one show me the code, or any tutorial? Thanks in advance!
Anatoliy Gatt
  • 2,501
  • 3
  • 26
  • 42
24
votes
3 answers

Add a UITapGestureRecognizer to a UIWebView

In iOS, is it possible to put a tap recognizer on a UIWebView, so that when someone single-taps the web view, an action gets performed? Code below doesn't seem fire handleTap when I tap my webView. Thanks. UITapGestureRecognizer *tap =…
user768339
  • 603
  • 2
  • 7
  • 8
24
votes
7 answers

How do I use UILongPressGestureRecognizer with a UICollectionViewCell in Swift?

I would like to figure out how to println the indexPath of a UICollectionViewCell when I long press on a cell. How can I do that in Swift? I have looked all over for an example of how to do this; can't find one in Swift.
webmagnets
  • 2,266
  • 3
  • 33
  • 60