【问题标题】:Why doesn't Xcode recognize -ignoreTouch:forEvent: in UITapGestureRecognizer subclass?为什么 Xcode 不能识别 -ignoreTouch:forEvent: 在 UITapGestureRecognizer 子类中?
【发布时间】:2013-07-27 19:59:30
【问题描述】:
根据documentation有一个方法-ignoreTouch:forEvent:。我需要模仿-pointInside:withEvent: 功能,使其仅处理特定形状的水龙头。
但是当我尝试调用这个方法时,Xcode 并不知道。没有自动完成功能,它会为未声明的方法提供错误。但是文档清楚地表明我们可以在 UITapGestureRecognizer 上调用 ignoreTouch:forEvent: 来忽略触摸。
编辑:文档说它有一个类扩展,但我也不能导入它。未找到:#import "UIGestureRecognizerSubclass.h"
【问题讨论】:
标签:
iphone
ios
ipad
uikit
uitapgesturerecognizer
【解决方案1】:
它是UIKit 的一部分,所以像这样导入它:
#import <UIKit/UIGestureRecognizerSubclass.h>
【解决方案2】:
似乎当我这样做时它有效:
#import <UIKit/UIGestureRecognizerSubclass.h>
@implementation OFShapeTapGestureRecognizer
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//[self ignoreTouch:[touches anyObject] forEvent:event];
// ... here, fancy logic.
if (ignore) {
self.state = UIGestureRecognizerStateCancelled;
}
}