4

我目前有一个 UIControl,它有许多子视图(图像、标签)。

不幸的是,当我使用 addTarget 等时,它没有检测到对子视图的触摸。

  [myCustomView addTarget:self action:@selector(touchedView:)
             forControlEvents:UIControlEventTouchUpInside];

UIControl 是否有可能检测子视图上的触摸,或者我应该以不同的方式接近它。

4

3 回答 3

23

请注意,不应接收触摸事件的 UIControl 的所有子视图本身必须将 userInteractionEnabled 设置为NO而不是 YES(这是默认设置)。

所以你必须在所有标签、图像等上设置它。

我只是遇到了这个问题,过了一会儿才弄清楚:)

于 2010-07-30T10:25:21.203 回答
0

Your method call is correct.

myCustomView should be the image or label being added.

于 2010-05-06T05:46:25.250 回答
0
[myCustomView setUserInteractionEnabled:YES];
于 2010-05-06T07:10:23.087 回答