关于UIScrollView不能响应UITouch事件的解决办法
2016-04-25 09:46
543 查看
这个不用多说直接上代码。
原因是:UIView的touch事件被UIScrollView捕获了。
解决办法:让UIScrollView将事件传递过去。于是最简单的解决办法就是加一个UIScrollView的category。这样每个用到UIScrollView的地方只要导入这个category就可以直接响应相关的touch事件了。
类似问题:在论坛看见很多人说UIImageView也没办法响应,我没尝试过,不过我想解决办法和原因都是一样的。 如果有人尝试过,不一样,欢迎批评指正。
原因是:UIView的touch事件被UIScrollView捕获了。
解决办法:让UIScrollView将事件传递过去。于是最简单的解决办法就是加一个UIScrollView的category。这样每个用到UIScrollView的地方只要导入这个category就可以直接响应相关的touch事件了。
类似问题:在论坛看见很多人说UIImageView也没办法响应,我没尝试过,不过我想解决办法和原因都是一样的。 如果有人尝试过,不一样,欢迎批评指正。
#import "UIScrollView+UITouch.h" @implementation UIScrollView (UITouch) - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [[self nextResponder] touchesBegan:touches withEvent:event]; [super touchesBegan:touches withEvent:event]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [[self nextResponder] touchesMoved:touches withEvent:event]; [super touchesMoved:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [[self nextResponder] touchesEnded:touches withEvent:event]; [super touchesEnded:touches withEvent:event]; } @end
相关文章推荐
- 232. Implement Queue using Stacks
- Windows 10年度更新Anniversary Update预览版开始推送,版本号Build 14328
- 浙江省赛e题Modulo Query
- easyui缩放后的拖拽问题
- FlashBuilder4.7非正常关闭导致不能启动的解决
- 设计模式读书笔记之建造者模式(Builder)
- 代码生成UIButton控件
- UIViewController原理详解
- iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。
- (4.6.3.2)Android UI 优化——使用HierarchyViewer工具
- (4.6.3.1)【Android工具】被忽略的UI检视利器:Hierarchy Viewer
- UITableView滑动删除
- stringbuffer和stringbuilder的区别
- 【收藏用】切勿转载-StringBuffer和StringBuilder的区别
- EasyUI-Datagrid行内编辑
- 为一个下拉框绑定value和text
- 如何创建一个UITableView(步骤详解 没有任何编程基础都能学会 )
- 推荐五个最好的MySQL GUI工具
- 推荐五个最好的MySQL GUI工具
- Android Material Design新UI控件使用大全 二