我目前有一个 UIControl,它有许多子视图(图像、标签)。
不幸的是,当我使用 addTarget 等时,它没有检测到对子视图的触摸。
[myCustomView addTarget:self action:@selector(touchedView:)
forControlEvents:UIControlEventTouchUpInside];
UIControl 是否有可能检测子视图上的触摸,或者我应该以不同的方式接近它。
请注意,不应接收触摸事件的 UIControl 的所有子视图本身必须将 userInteractionEnabled 设置为NO而不是 YES(这是默认设置)。
所以你必须在所有标签、图像等上设置它。
我只是遇到了这个问题,过了一会儿才弄清楚:)
Your method call is correct.
myCustomView should be the image or label being added.
[myCustomView setUserInteractionEnabled:YES];