iOS 的UIView 的hitTest的分析
2016-03-24 00:00
435 查看
hitTest的用法:
(1)当在一个view上添加一个屏蔽罩,但又不影响对下面view的操作,也就是可以透过屏蔽罩对下面的view进行操作,这个函数就很好用了。
将下面的函数添加到UIView的子类中,也就是屏蔽罩类中即可。
-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
if (hitView == self)
{
return nil;
}
else
{
return hitView;
}
}
(2)父视图中有布局重叠的且都可响应用户操作的对象,如:ScrollView and Button,如果Button在ScrollView下面,正常情况下Button是不会成为第一响应者的,如果想让Button可以响应在其布局内的触摸事件,可以在Button和ScrollView的父View中重写hitTest:withEvent方法
(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
CGPoint hitPoint = [_testButton convertPoint:point fromView:self];
if ([_testButton pointInside:hitPoint withEvent:event])
return _testButton;
return [super hitTest:point withEvent:event];
}//_testButton是指定响应对象的 弱 引用
(1)当在一个view上添加一个屏蔽罩,但又不影响对下面view的操作,也就是可以透过屏蔽罩对下面的view进行操作,这个函数就很好用了。
将下面的函数添加到UIView的子类中,也就是屏蔽罩类中即可。
-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
if (hitView == self)
{
return nil;
}
else
{
return hitView;
}
}
(2)父视图中有布局重叠的且都可响应用户操作的对象,如:ScrollView and Button,如果Button在ScrollView下面,正常情况下Button是不会成为第一响应者的,如果想让Button可以响应在其布局内的触摸事件,可以在Button和ScrollView的父View中重写hitTest:withEvent方法
(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
CGPoint hitPoint = [_testButton convertPoint:point fromView:self];
if ([_testButton pointInside:hitPoint withEvent:event])
return _testButton;
return [super hitTest:point withEvent:event];
}//_testButton是指定响应对象的 弱 引用
相关文章推荐
- 用SoapUI进行Webservice的性能压力测试
- iPhone6&iPhone6 Plus CSS3 Media Queries
- Patchwork & Quilting(拼布和绗缝)
- What is Bluetooth Profile[待翻译]
- Qt在线技术交流之OpenGL、Quick以及所经历项目开发心得分享
- Location Services and Maps Programming Guide 纪录
- UESTC 1144 Big Brother
- HDU5288 OO’s Sequence 二分
- Quartz学习笔记(五) quartz扩展druid连接池
- leetcode_063 Unique Paths II
- UICollectionView
- iOS--UITableView 显示二级菜单
- leetcode_062 Unique Paths
- iOS之UIAlertView的使用
- UIBezierPath精讲
- UITableViewCell的使用介绍
- iOS UITextField的基本用法
- 封装简单的equery
- 有了Auto Layout,为什么你还是害怕写UITabelView的自适应布局?
- 修改UIBarButtonItem字体大小、颜色等相关属性