作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我手动创建了一个对象(文件 -> 新建 -> NewClass -> UITableViewCell)并向其中添加了 .xib。创建的cell有几个标签,见图
之后我在其他类中使用这个对象
myCell * showHere;
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"myCell" owner:self options:nil];
showHere = [nib objectAtIndex:0];
如何在此单元格上添加 UIlabel 的gestureRecognizer?
我已经尝试过这个:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;
[showHere.monday addGestureRecognizer:longPress];
还有这个
-(void)handleLongPress:(UILongPressGestureRecognizer*)recognizer {
NSLog(@"label has pressed");
我需要通过按单个标签来捕捉 Action 。是否可以?对不起我的英语。
最佳答案
只需在
之后添加YourLabel.userinteractionEnabled = YES
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer 分配]
initWithTarget: self
Action :@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;
启用对标签的触摸
祝你好运
关于objective-c - 如何为手动创建的对象添加gestureRecognizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11721563/
我是一名优秀的程序员,十分优秀!