简体   繁体   English

如何完全删除手势识别器

[英]how to completely remove gesture recognizers

I'm trying to remove three gesture recognizers attached to a uiscrollview. 我正在尝试删除附加到uiscrollview的三个手势识别器。

I list them using 我用它们列出它们

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

I get the three listed. 我列出了三个。

Then I remove them with: 然后我删除它们:

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

Then I list them again, and get a zero count. 然后我再次列出它们,并获得零计数。 They should be gone/removed, right ? 它们应该被删除/删除,对吧? Why would then the view continue to respond (and gesture methods getting called) to the same touches/swipes. 那么为什么视图会继续响应(并且调用手势方法)到相同的触摸/滑动。 Is there some kind of a "flushing" mechanism that needs to happen before they're gone for good ? 是否有某种“冲洗”机制需要在它们永远消失之前发生?

this is how they get created: 这是他们如何创建:

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];

thanks 谢谢

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

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

Adopt the UIGestureRecognizerDelegate protocol and implement the following method. 采用UIGestureRecognizerDelegate协议并实现以下方法。

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

Looks to me like you're adding the gesture recognizers to the view but removing them from theScrollView. 在我看来,你正在向视图中添加手势识别器,但是将它们从循环视图中删除。 Is this what you intended? 这是你的意图吗? You should be removing the gesture recognizers from self.view if you want those to stop. 您应该从self.view中删除手势识别器,如果您希望停止这些手势识别器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM