Objective c UIImageView的子类能否响应触摸事件?

Objective c UIImageView的子类能否响应触摸事件?,objective-c,uiimageview,touchesbegan,Objective C,Uiimageview,Touchesbegan,我知道其他人问了类似的问题,但我检查了一下,他们的问题和我的不一样 以下是customImageView中的代码 @implementation KeysTest - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self.userInteractionEnabled:YES]; self.image = [UIImage imageNamed:@"whiteke

我知道其他人问了类似的问题,但我检查了一下,他们的问题和我的不一样

以下是customImageView中的代码

@implementation KeysTest

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
    [self.userInteractionEnabled:YES]; 
 self.image = [UIImage imageNamed:@"whitekey.gif"];
}
return self;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"test!");
}

出于某种原因,它无法识别userInteractionEnabled方法。另外,codeSense功能对ToucheSBegind方法不起作用。

我不确定您的代码示例是否能正确编译。但是评论家Sam是正确的,
[self.userInteractionEnabled:YES]
不是一个合适的函数。这需要更改为

self.userInteractionEnabled = YES;

可能是输入错误,但第6行应为self.userInteractionEnabled=YES或[self-setUserInteractionEnabled:YES]