我有一个子类
UIImageView
我需要知道什么时候被触摸。(下面是完整的代码。)我已经找到并阅读了这两者
this
和
this
. 它们有点用处,但都没有真正起作用。不仅是我的
touchesBegan:withEvent:
方法未被调用,正在按下图像后面的按钮。
这是我的代码:
头文件:
@interface MathKeyboardKey : UIImageView
{
}
@end
实施文件:
@implementation MathKeyboardKey
- (id)initWithImage:(UIImage *)image
{
if (self = [super initWithImage:image])
{
//init here
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"-- I AM TOUCHED --");
}
- (void)dealloc
{
[super dealloc];
}
@end
呼叫代码:
{
self.userInteractionEnabled = NO;
mathKeyboardAccess = [[MathKeyboardKey alloc] initWithImage:[UIImage imageNamed:@"mathKey.png"]];
CGRect frm = mathKeyboardAccess.frame;
frm.origin = CGPointMake(80, 171);
mathKeyboardAccess.frame = frm;
mathKeyboardAccess.userInteractionEnabled = YES;
[self addSubview:mathKeyboardAccess];
}
正在将此视图添加为另一个视图的子视图
MathKeyboard
)超级视图不能启用用户交互,因为它覆盖了另一个视图(系统键盘)。当我试图添加
MathKeyboardKey
在系统键盘视图中,它不显示。如果我尝试使用ui按钮,它将永远不会出现,无论我将它放在哪个视图中。
问题是,如果不明显的话,我该如何检测到这里面的触摸?
ui图像视图
子类?