子View不响应touch事件,让父View响应touch事件
2014-08-06 22:49
423 查看
在工作中遇到一个button上有一个uiImageview控件,但是功能要求,点击图片的时候,和button执行相同的功能
首先想到方法是 button上addTarget,然后在uiImageview上加一个手势,同时指向同一个方法,太傻逼
经过查资料,发现,直接将uiImageview对象的userInteractionEnabled属性,直接设置为NO,则touch事件就直接传到父View
类似这样,当你点击subview的时候,就可以运行hello:方法
首先想到方法是 button上addTarget,然后在uiImageview上加一个手势,同时指向同一个方法,太傻逼
经过查资料,发现,直接将uiImageview对象的userInteractionEnabled属性,直接设置为NO,则touch事件就直接传到父View
<span style="font-size:18px;"> UIButton *btn = [[UIButton alloc]init]; [btn setFrame:CGRectMake(40 , 40 , 200, 40)]; btn.layer.borderWidth = 2; [viewParent addSubview:btn]; [btn addTarget:self action:@selector(hello:) forControlEvents:UIControlEventTouchUpInside]; UIView *subView = [[UIView alloc]init]; [subView setFrame:CGRectMake(0, 0, 20, 20)]; subView.layer.borderWidth = 2; subView.userInteractionEnabled = NO; [btn addSubview:subView];</span>
类似这样,当你点击subview的时候,就可以运行hello:方法
相关文章推荐
- 父级view 不响应touch事件 子view相应事件
- 解决小米系统下ViewPager、ScrollView内嵌套WebView时,Touch事件不响应的问题
- 可以响应touch事件的TableView--HYTableView
- UIScrollView无法响应touch事件的解决办法
- UIScrollView无法响应touch事件的解决办法
- 『IOS』UIScrollView无法响应touch事件的解决办法
- 解决UIScrollView,UIImageView等控件不能响应touch事件的问题
- UIScrollView不能响应touch事件的解决办法
- 在view上响应手势和touch事件
- UIScrollView不能响应touch事件的解决办法
- UIScrollView UICollectionView 无法响应touch事件
- 如何让UIScrollView里面的UIImageView响应touch事件
- UIScrollView无法响应touch事件解决方法
- scrollview/tableview 无法响应touch事件
- 让UITableView响应touch事件
- 如何屏蔽父view的touch事件到,并且响应self的touch
- 解决UIScrollView,UIImageView等控件不能响应touch事件的问题
- 关于UIScrollview不能响应touch事件的解决办法
- UIScrollView无法响应touch事件的解决办法
- 细说UIScrollView上的Touch 事件 推荐