我试图将手势识别器附加到我自己的UILabel的子类中,但它不起作用。你能帮助我了解什么是错的代码是否有可能将UITapGestureRecognizer附加到UILabel子类
@interface Card : UILabel {
}
- (void) addBackSideWord;
@end
#import "Card.h"
@implementation Card
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(addBackSideWord)];
[tapRecognizer setNumberOfTouchesRequired:2];
[tapRecognizer setDelegate:self];
[self addGestureRecognizer:tapRecognizer];
}
return self;
}
- (void) addBackSideWord {
//do something
}
@end
谢谢您的解答!我花了24小时阅读文档,并没有注意到这个简单的伎俩。只希望它对我有用:) – Michael 2011-06-15 09:50:46