UIImageView
いつ触れられるかを知る必要があるサブクラスがあります。(以下の完全なコード。)私はこれとこれの両方を見つけて読んだ。それらはやや有用でしたが、どちらも実際には機能しませんでした。メソッドが呼び出されていないだけでなく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
と、表示されません。UIButtonを使用しようとすると、どのビューに配置しても表示されません。
明らかでない場合の質問は、このUIImageView
サブクラスのタッチをどのように検出するかです。