如何取消或重置UIGestureRecognizer
?问题是,如果我在手势期间将waitForSomething
设置为NO
,则下一个事件为UIGestureRecognizerStateChanged
。但第一个事件应该是UIGestureRecognizerStateBegan
。
我的代码:
- (void) panned:(UIPanGestureRecognizer *) recognizer {
if (waitForSomething) {
// cancel or reset the recognizer!
// because the next event should be UIGestureRecognizerStateBegan and not UIGestureRecognizerStateChanged
return;
}
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:
// important initialisation code
break;
case UIGestureRecognizerStateChanged:
// do something
break;
}
}
谢谢你的帮助!
答案 0 :(得分:39)
我明白了! : - )
也许其他人遇到了这个问题,这是解决方案:
if (waitForSomething) {
recognizer.enabled = NO;
recognizer.enabled = YES;
return;
}
下一个活动将是UIGestureRecognizerStateFailed
,然后是UIGestureRecognizerStateBegan
。
答案 1 :(得分:0)
if waitForSomething {
recognizer.isEnabled = false
recognizer.isEnabled = true
return
}
答案 2 :(得分:0)
如果您需要在多个地方进行此操作:
在Swift
扩展UIGestureRecognizer
{
func cancel(){
isEnabled =假
isEnabled = true
}
}