繁体   English   中英

是否可以在自定义UIView子视图的标签中添加GestureRecognizer

[英]is it possible to add a GestureRecognizer to a label in a custom UIView subview

我正在重构我采用的ViewController并在控制器代码中创建UIView 我想将其移至自定义UIView但希望在控制器中处理Gesture Recognizer。

我有一个具有自定义UIViewItemViewController 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
{
    ...
}

ItemViewControllerItemViewController自定义视图中)。

但这似乎不起作用。 是否可以将GestureRecognizer添加到标签中,该标签是ViewController中子视图的属性? 有什么明显的我做错了吗?

您需要在标签上将userInteractionEnabled设置为YES ,以使其接受触摸(并因此使手势接收触摸)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM