Mic*_*ael 32 iphone xcode ios4 ios
我正在尝试将手势识别器附加到我自己的类,这是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
Run Code Online (Sandbox Code Playgroud)
Vla*_*mir 78
您的代码应该可以正常工作,您可能需要修复的唯一问题是默认情况下UILabel禁用了用户交互,因此手势识别器不会收到任何触摸事件.尝试通过在代码中添加此行来手动启用它(例如在init方法中):
self.userInteractionEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
Jha*_*iya 15
是的,这是可能的,任何继承自的类UIView
.
不要忘记启用用户交互.
self.userInteractionEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9024 次 |
最近记录: |