Ios 不应接收呼叫的触摸
我在网上看到很多关于它的问题,尤其是关于StackOverflow的问题。 我测试了很多给定的答案,但在我的情况下,什么都不起作用 My类实现协议Ios 不应接收呼叫的触摸,ios,uigesturerecognizer,Ios,Uigesturerecognizer,我在网上看到很多关于它的问题,尤其是关于StackOverflow的问题。 我测试了很多给定的答案,但在我的情况下,什么都不起作用 My类实现协议UIgestureRecognitzerDelegate: @interface CDMapViewController : CDViewController <UIGestureRecognizerDelegate> 我已在第一个方法中正确初始化UIgestureRecognitor,该方法正确调用了第二个、第三个和第四个方法: - (
UIgestureRecognitzerDelegate
:
@interface CDMapViewController : CDViewController <UIGestureRecognizerDelegate>
我已在第一个方法中正确初始化UIgestureRecognitor,该方法正确调用了第二个、第三个和第四个方法:
- (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 */
}
。。。它不记录-未调用。。。为什么?您需要为
方法调用super
实现
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
gesture_dragging = NO;
}
... and so on.
这些方法需要在视图上实现,而不是在视图控制器上实现
选择你想要的姿势。就其本身而言,UIGestureRecognizer
做的并不多,所以选择像UITapGestureRecognizer
这样的一个。接下来,使用指定的初始值设定项实现手势识别器
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myMethod:)];
最后,实现myMethod:
-(void)myMethod:(UITapGestureRecognizer *)recognizer
{
// Whatever this does.
}
谢谢你的快速回答,我现在就这么做。。。但这并不能解决问题。它不调用should receivetouch功能。您想要什么样的手势?水龙头?您需要使用UIgestureRecognitizer
的子类。是的,我想点击一下,但在MKMapView上选择覆盖。我想调用shouldReceiveTouch以禁用mapView顶部信息栏上的触摸。我已经编辑了答案–您需要创建一个UITapGestureRecognitizer
。是的,我尝试了这个,但我想避免使用选择器,因为“UItouch”不是传入参数。。但是,很明显,我别无选择。。。我检查答案是否有效。手势识别器是用来取代触摸开始:
和所有这些方法的。您通常只需要实现其中一个。
-(void)myMethod:(UITapGestureRecognizer *)recognizer
{
// Whatever this does.
}