如何以编程方式设置UIGestureRecognizer的状态?

时间:2014-03-16 14:14:17

标签: ios uigesturerecognizer uipangesturerecognizer

我使用的是UIGestureRecognizer:

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

现在,我希望能够将GestureRecognizer的状态设置为UIGestureRecognizerStateEnded,这样当我输入

- (void)foldToGallery:(UIPanGestureRecognizer*)gesture

它将执行以下代码:

if (gesture.state == UIGestureRecognizerStateEnded

并忽略手势的其余部分,直到我开始新的

2 个答案:

答案 0 :(得分:3)

也许你可以设置gesture.enabled = NO
这将导致状态`UIGestureRecognizerStateCancelled(documentation)。也许您可以检查此状态并在之后再次启用它。

答案 1 :(得分:2)

它可能比设置enabled更脆弱,但KV​​C也有效:

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

如果您不希望识别器转换为已取消,这将非常有用。