gpt4 book ai didi

objective-c - 禁用手势识别器

转载 作者:IT老高 更新时间:2023-10-28 11:49:47 25 4
gpt4 key购买 nike

我有两种类型的识别器,一种用于点击,一种用于滑动

UIGestureRecognizer *recognizer;

//TAP
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(numTap1:)];
[(UITapGestureRecognizer *)recognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:recognizer];
self.tapRecognizer = (UITapGestureRecognizer *)recognizer;
recognizer.delegate = self;
[recognizer release];

//SWIPE RIGHT
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
self.swipeRightRecognizer =(UISwipeGestureRecognizer *)recognizer;
swipeRightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRightRecognizer];
self.swipeRightRecognizer = (UISwipeGestureRecognizer *)recognizer;
[recognizer release];

使用此功能,我可以禁用对某些对象的点击。

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

if ((touch.view == loseView) || (touch.view == subBgView) || (touch.view == btnAgain)) {

return NO;
}

return YES;
}

如何禁用滑动?

非常感谢!

最佳答案

UIGestureRecognizer 有一个名为enabled 的属性。这应该足以禁用您的滑动:

swipeGestureRecognizer.enabled = NO;

编辑:对于 Swift 5

swipeGestureRecognizer.isEnabled = false

关于objective-c - 禁用手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5991250/

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