[英]is it possible to add a GestureRecognizer to a label in a custom UIView subview
我正在重构我采用的ViewController
并在控制器代码中创建UIView
。 我想将其移至自定义UIView
但希望在控制器中处理Gesture Recognizer。
我有一个具有自定义UIView
的ItemViewController
。 在ItemController
,我想做类似的事情:
ItemView *itemView = [[ItemView alloc] initWithFrame:CGRectMake(30.0f,_runningYPosition,100.0f, 50.0f)];
UITapGestureRecognizer *tapRecognizer2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)];
itemView.miHeaderLabel.tag = [item itemID];
[itemView.miHeaderLabel addGestureRecognizer: tapRecognizer2];
那引用
- (void)tapRecognized:(id)sender
{
...
}
在ItemViewController
( ItemViewController
自定义视图中)。
但这似乎不起作用。 是否可以将GestureRecognizer添加到标签中,该标签是ViewController中子视图的属性? 有什么明显的我做错了吗?
您需要在标签上将userInteractionEnabled
设置为YES
,以使其接受触摸(并因此使手势接收触摸)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.