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
23
votes
4 answers

Get swipe direction in Cocoa Touch

I am trying to catch a gesture but it does not work. Here is my code: UISwipeGestureRecognizer *recognizer; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; [recognizer…
Csabi
  • 3,097
  • 17
  • 59
  • 107
23
votes
1 answer

Button tap and long press gesture

I'm having a little trouble with the gestures. I'm trying to use both tap and long press on the same button, so I've used @IBAction func xxx (sender: UITapGestureRecognizer) and @IBAction func xxx (sender: UILongPressGestureRecognizer) but my…
Alvin Wan
  • 233
  • 1
  • 2
  • 5
23
votes
1 answer

Do I need to release a gesture recognizer?

If I add a gesture recognizer to a table cell called cell, e.g.: UILongPressGestureRecognizer *_longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self…
23
votes
2 answers

Subclassing UIGestureRecognizer with Swift and Xcode 6 - how do I import UIGestureRecognizerSubclass.h?

You can't write to self.state in the subclass unless you import UIGestureRecognizerSubclass.h as indicated here. In a Swift environment, I'm confused how I'd go about importing this. I tried import UIGestureRecognizerSubclass.h, and without the .h,…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
22
votes
3 answers

Can I disable the UIPageViewController's page border gesture recognizers? And keep the swipe one?

I see that I can remove all of the UIPageViewController gestures, but what if I only want to remove the tap gesture on the edges? And keep the swipe gesture? Is this possible? Thanks
Westley
  • 1,143
  • 14
  • 27
22
votes
4 answers

Disable 2 finger scrolling in UIScrollView

I'd like to disable two-finger scrolling in my UIScrollView. I subclassed it and tweaked its built-in gesture recognizers with the following code: for (UIGestureRecognizer *mgestureRecognizer in scroller.gestureRecognizers) { if…
stipoy
  • 251
  • 2
  • 5
22
votes
3 answers

Resize UIView While It Is Rotated with Transform

When my UIView is rotated with transform property (CGAffineTransformMakeRotation), I need to drag one of its corners, say bottom right, to resize it. During this process when user drags the corner, the view's corner must follow user's finger and…
Vad
  • 3,658
  • 8
  • 46
  • 81
22
votes
5 answers

Table view doesn't scroll when I use gesture recognizer

My app has a table view (with a scroll-into of course) and this view slides on and off with a gesture recognizer (like on the Facebook app). If I use a button to slide [the table view onto the screen], it works fine but when I use a gesture…
user2576304
  • 231
  • 1
  • 2
  • 4
22
votes
8 answers

UITapGestureRecognizer Programmatically trigger a tap in my view

Edit: Updated to make question more obvious Edit 2: Made question more accurate to my real-world problem. I'm actually looking to take action if they tap anywhere EXCEPT in an on-screen text-field. Thus, I can't simply listen for events within…
Matt H.
  • 10,438
  • 9
  • 45
  • 62
21
votes
7 answers

MPMoviePlayerController's view does not recognize touch

This is my code: _mediaPlayer = [[MPMoviePlayerController alloc] init]; _mediaPlayer.controlStyle = MPMovieControlStyleNone; _mediaPlayer.shouldAutoplay = NO; [_mediaPlayer.view setFrame: CGRectMake(5, 5, 600,400)]; [playerHolder addSubview:…
beryllium
  • 29,669
  • 15
  • 106
  • 125
21
votes
5 answers

super respondsToSelector: returns true but actually calling super (selector) gives "unrecognized selector sent to instance"

OK, I am a little confused. I have a subclass of UIScrollView, which is my attempt at a horizontally scrolling "table view" like UI element. UIScrollView itself sets up UIGestureRecognizers it uses internally, and it appears to set itself up as the…
20
votes
7 answers

iOS adding tapGesture to multiple Views

I have multiple views defined in my main view. I want to add single tap gesture to all these views. Below is the code I have written, but this registers a tap gesture to the last view that I add. So in the code below, tap is registered only for…
Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
20
votes
7 answers

Combining a UILongPressGestureRecognizer with a UIPanGestureRecognizer

I d'like to combine a UILongPressGestureRecognizer with a UIPanGestureRecognizer. The UIPanGestureRecognizer should start with a long press. Is there a simple way to do this? or do I really have to write my own gesture recognizer? I wan't something…
20
votes
2 answers

Simultaneous gesture recognition for specific gestures

I'm trying to enable simultaneous gesture recognition but only for the UIPinchGestureRecognizer and UIRotationGestureRecognizer gestures. I don't want it to work for any other gestures. If I set the following property to true it allows all gestures…
SpaceShroomies
  • 1,635
  • 2
  • 17
  • 23
20
votes
6 answers

How to receive touches on a UICollectionView in the blank space around all cells

I have a UICollectionView that has different items in it. When I tap on an item, I use: -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath to figure out what was touched and then basically…
Blane Townsend
  • 2,888
  • 5
  • 41
  • 55