解决ScrollView设置delaysContentTouches为NO后,按在button上scrollview无法滑动问题

来源:互联网 发布:深圳市建筑工务署 知乎 编辑:程序博客网 时间:2024/06/06 08:24
 

解决ScrollView设置delaysContentTouches为NO后,按在button上scrollview无法滑动问题 

标签: ios开发
 327人阅读 评论(0) 收藏 举报
 分类:
[objc] view plain copy
  1.   

在ScrollView中如果添加了button,一开始会出现button的按下效果不明显,此时会设置scrollView.delaysContentTouches = NO;来关闭延迟响应, 但是又会出现手指放在button上去做滑动,但是scrollView只会响应button的点击事件,而不去进行滑动.

要解决这个办法,需要重载UIScrollView这个类,并实现其中的touchesShouldCancelInContentView:方法,在方法中return YES就好啦.

但是会有人发现,为什么我重载了这个方法,但是打了断点却发现不调用这个方法呢?

看下外国友人的问答:

From what I've seen, you don't get touchesShouldCancelInContentView: or touchesShouldBegin:withEvent:inContentView: callbacks unless you have delaysContentTouches set to NO:

scrollView.delaysContentTouches = NO;

这段说你重载的这俩方法,必须同时设置scrollView.delaysContentTouches = NO;

I got stuck on this for a while incase you ever read this, you need to have both the following properties set before touches in touchesShouldCancelInContentView will fire
scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;
Just having scrollView.delaysContentTouches = NO wont fire if scrollView.canCancelContentTouches = NO


下边又回复说,必须同时设置以下两个才可以:
scrollView.delaysContentTouches = NO;

scrollView.canCancelContentTouches = YES;

验证好使,快来试试吧~

0
0 0
原创粉丝点击