YogevSitton
YogevSitton

Reputation: 10108

How to programmatically set the state of a UIGestureRecognizer?

I use a UIGestureRecognizer:

panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandler:)];
panGestureRecognizer.delegate = self;

Now, I want to be able to set the state of the GestureRecognizer to UIGestureRecognizerStateEnded so when I enter

- (void)foldToGallery:(UIPanGestureRecognizer*)gesture

It will perform the code under:

if (gesture.state == UIGestureRecognizerStateEnded

and ignore the rest of the gesture until I will start a new one

Upvotes: 4

Views: 2774

Answers (2)

user3163025
user3163025

Reputation:

It may be a bit more fragile than setting enabled, but KVC works, too:

[gesture setValue:@(UIGestureRecognizerStateEnded) forKey:@"state"];

This would be useful if you don't want your recognizer to transition to cancelled.

Upvotes: 2

lootsch
lootsch

Reputation: 1865

Maybe you can set gesture.enabled = NO
That will lead to the state `UIGestureRecognizerStateCancelled (documentation). Maybe you can check on this state and enable it again afterwards.

Upvotes: 3

Related Questions