【问题标题】:Can a subclass of UIImageView respond to touch events?UIImageView 的子类可以响应触摸事件吗?
【发布时间】:2011-08-15 03:00:34
【问题描述】:

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

这是来自 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]

标签: objective-c uiimageview touchesbegan


【解决方案1】:

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

self.userInteractionEnabled = YES;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-22
    • 1970-01-01
    • 2011-01-23
    相关资源
    最近更新 更多