如何完全删除手势识别器

时间:2012-03-02 18:45:06

标签: objective-c ios uigesturerecognizer

我正在尝试删除附加到uiscrollview的三个手势识别器。

我使用

列出它们
NSArray * activeScrollViewGRecs = [theScrollView gestureRecognizers];
NSLog (@"activeScrollViewGRecs count: %d",[activeScrollViewGRecs count]);

我列出了三个。

然后我用以下方法删除它们:

for (UIGestureRecognizer *recognizer in activeScrollViewGRecs)
{
    NSLog (@"recognizer: %@",recognizer.description);
    recognizer.enabled = NO;
    [theScrollView removeGestureRecognizer:recognizer];
}

然后我再次列出它们,并获得零计数。它们应该被删除/删除,对吧? 那么为什么视图会继续响应(并且调用手势方法)到相同的触摸/滑动。是否有某种“冲洗”机制需要在它们永远消失之前发生?

这就是它们的创建方式:

tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handle1:)];
tapGesture.cancelsTouchesInView = NO; tapGesture.delaysTouchesEnded = NO; 
tapGesture.numberOfTouchesRequired = 2; tapGesture.numberOfTapsRequired = 2;     
[self.view addGestureRecognizer:tapGesture]; [tapGesture release];

swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handle2:)];
swipeGesture.cancelsTouchesInView = NO; swipeGesture.delaysTouchesEnded = NO; swipeGesture.delegate = self;
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeGesture]; [swipeGesture release];

感谢

3 个答案:

答案 0 :(得分:1)

为什么不使用以下手势委托来停止任何手势:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;

答案 1 :(得分:0)

在我看来,您正在将手势识别器添加到视图中,但将其从循环视图中删除。这是你的意图吗?你应该从self.view中删除手势识别器,如果你想让它们停止。

答案 2 :(得分:0)

采用UIGestureRecognizerDelegate协议并实施以下方法。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if (to completely remove gesture recognizers)
        return NO;
    else 
        return YES;
}