gpt4 book ai didi

ios - shouldReceiveTouch 未调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:14:36 24 4
gpt4 key购买 nike

我在网上看到很多关于它的问题,尤其是在 StackOverflow 上。我测试了许多给定的答案,但就我而言,没有任何效果。

我的类实现协议(protocol)UIGestureRecognizerDelegate:

@interface CDMapViewController : CDViewController <UIGestureRecognizerDelegate>

下面的方法是我类的@implentation中的xcode自动补全写的

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
shouldReceiveTouch:(UITouch *)touch {
NSLog(@"not called");
return NO;
}

我已经在正确调用第二、第三和第四方法的第一个方法中正确初始化了 UIGestureRecognizer:

- (void)initGestureOnMap {
UIGestureRecognizer *gestureRecognizer = [[UIGestureRecognizer alloc] init];
gestureRecognizer.delegate = self;
[self.view addGestureRecognizer:gestureRecognizer];
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
gesture_dragging = NO;
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
gesture_dragging = YES;
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
if (gesture_dragging || [touches count] != 1) return;
/* bla bla bla */
}

...它不记录 – 不调用...为什么?

最佳答案

您需要为 touches 方法调用 super 实现。

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  {
[super touchesBegan:touches withEvent:event];
gesture_dragging = NO;
}

... and so on.

这些方法需要在您的 View 上实现,而不是在您的 View Controller 上实现。

选择您想要的手势类型。就其本身而言,UIGestureRecognizer 并没有做太多事情,所以选择像 UITapGestureRecognizer 这样的一个。接下来,使用指定的初始化程序实现您的手势识别器。

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myMethod:)];

最后,实现myMethod:

-(void)myMethod:(UITapGestureRecognizer *)recognizer
{
// Whatever this does.
}

关于ios - shouldReceiveTouch 未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15947676/

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