您的位置:首页 > 产品设计 > UI/UE

UIView无法响应点击事件问题分析

2016-04-15 13:20 501 查看
做项目的时候有个需求是:点击一个按钮出现一个浮层,界面变暗。我的实现方法是自定义一个view1让它填满整个界面,然后调整view1的背景色和透明度,再在上面加上浮层的view2。可是结果发现我点击自定义的view1,点击事件直接穿透过去了,不管怎么设置透明度啊啥的都不行。后来寻求StackOverFlow的帮助,找到下面这段话:

Looking at the test project, I believe your problem in the way you create TestView, you do not specify the frame for it, so basically the parent view is 0 size, and the subviews you see from XIB extending out of the parent view and thus do not get anything in responder chain.
直白点说就是,你在给view添加gesture事件之前,要先指定view及其各个parentView的尺寸,否则无法添加成功。后来发现我在给view1添加gesture之前没有初始化它父视图的frame,指定之后,手势添加成功!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息