iOS横向滚动的scrollView和系统pop手势返回冲突的解决办法
2015-10-20 17:18
555 查看
原文链接:/article/10585659.html
![](https://oscdn.geek-share.com/Uploads/Images/Content/202011/18/18044541587b58343fb1c76ecc415ffa)
直接上解决办法:
1.首先自定义一个scrollView,比如:CustomScrollView,遵守<UIGestureRecognizerDelegate>协议,然后在实现文件中写如下代码:
2.那个横向滚动的scrollView继承这个自定义scrollView,也就是CustomScrollView
原理:
scrollView的pan手势会让系统的pan手势失效,所以我们只需要在系统手势失效且scrollView的位置在初始位置的时候让两个手势同时启用就可以了
直接上解决办法:
1.首先自定义一个scrollView,比如:CustomScrollView,遵守<UIGestureRecognizerDelegate>协议,然后在实现文件中写如下代码:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { // 首先判断otherGestureRecognizer是不是系统pop手势 if ([otherGestureRecognizer.view isKindOfClass:NSClassFromString(@"UILayoutContainerView")]) { // 再判断系统手势的state是began还是fail,同时判断scrollView的位置是不是正好在最左边 if (otherGestureRecognizer.state == UIGestureRecognizerStateBegan && self.contentOffset.x == 0) { return YES; } } return NO; }
2.那个横向滚动的scrollView继承这个自定义scrollView,也就是CustomScrollView
原理:
scrollView的pan手势会让系统的pan手势失效,所以我们只需要在系统手势失效且scrollView的位置在初始位置的时候让两个手势同时启用就可以了
相关文章推荐
- iOS 取随机数 对4取余
- iOS Autolayout之Masonry解读
- iOS开发见闻-第2期
- 关于ios的手势识别(GestureRecognizers)讲解
- (NO.00001)iOS游戏SpeedBoy Lite成形记(五)
- V8 ig V3 igrimace ios7 ios8一键新机 一键抹机 清理缓存 修改串号平安易贷 uber
- (NO.00001)iOS游戏SpeedBoy Lite成形记(五)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(五)
- 我的iOS学习历程 - 第九天
- 我们为什么要学习iOS?
- iOS ---打开iPhone照相机和相册
- iOS 简单的本地缓存
- iOS设计模式——MVC(Model-View-Controller)
- iOS 9 适配系列教程
- iOS 本地存储NSUserDefaults
- iOS设计模式——委托(delegate)
- iOS调试技巧
- iOS gif图显示问题
- iOS设计模式——Category
- iOS 打开网页URL