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

 

解决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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值