我正在重构我已采用的ViewController
并在控制器代码中创建UIView
。我想将其移至自定义UIView
,但想要在控制器中处理手势识别器。
我有ItemViewController
,其中包含自定义UIView
。在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
中的(不在自定义视图中)。
但它似乎不起作用。是否可以将GestureRecognizer添加到标签中,该标签是ViewController中子视图的属性?有什么明显的我做错了吗?
答案 0 :(得分:1)
您需要在标签上将userInteractionEnabled
设置为YES
才能接受触摸(因此手势接收触摸)。