开发者

iPhone UIControl and Subview

开发者 https://www.devze.com 2022-12-29 02:42 出处:网络
I currently have a UIControl, which has a number of subviews (image, label). Unfortunately when I use addTarget etc. It doesn\'t detect touches on the subviews.

I currently have a UIControl, which has a number of subviews (image, label).

Unfortunately when I use addTarget etc. It doesn't detect touches on the subviews.

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

Is it possible for the UIControl to detect touches on subviews or开发者_JAVA技巧 should i be approaching it differently.


Just note that all subviews of a UIControl which shouldn't receive touch events themselves must have userInteractionEnabled set to NO and not YES (which is the default).

So you must set this on all labels, images, etc.

I just ran into this and figured it out after a while :)


Your method call is correct.

myCustomView should be the image or label being added.


[myCustomView setUserInteractionEnabled:YES];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号