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,指定之后,手势添加成功!
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,指定之后,手势添加成功!
相关文章推荐
- jquery实现移动端点击图片查看大图特效
- 为body标签和document.body都添加点击事件后仅Firefox弹出了两次
- Android中捕获TTextView文本中的链接点击事件方法
- JavaScript给按钮绑定点击事件(onclick)的方法
- iOS应用开发中UIView添加边框颜色及设置圆角边框的方法
- CALayer与UIView的关系
- UIView的bounds和frame区别
- uiview
- uiview生命周期
- UIView翻译 (参考)
- iOS 转变UIView到UIImage
- UIView动画
- initWithFrame 和 initWithCoder
- [CS193P] 第六堂課摘要及心得筆記
- UI第一天
- 棋盘
- ios实现button变换颜色并可以放大、缩小、旋转
- uiview contentViewmode
- iphone开发小记 基础知识2
- iphone开发小记 基础知识3