0
我知道别人也提过类似的问题,但我查了一下,他们的问题和我的不一样。UIImageView的子类可以响应触摸事件吗?
下面是从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功能对touchesBegan方法不起作用。
可能是拼写错误,但第6行应该是self.userInteractionEnabled = YES或[self setUserInteractionEnabled:YES] – Sam