gpt4 book ai didi

objective-c - 如何完全删除手势识别器

转载 作者:可可西里 更新时间:2023-11-01 03:59:41 27 4
gpt4 key购买 nike

我正在尝试删除附加到 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];
}

然后我再次列出它们,结果为零。他们应该消失/移除,对吧?那么为什么 View 会继续响应(并调用手势方法)相同的触摸/滑动。在它们永远消失之前是否需要某种“刷新”机制?

它们是这样创建的:

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

谢谢

最佳答案

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

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

关于objective-c - 如何完全删除手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9538686/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com