分类:
版权声明:本文为博主原创文章,未经博主允许不得转载。
在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