问题表现:
uiscrollerView 上添加UIButton 表情按钮
不知道为什么uiscrollerView 点击的时候应该有个150ms的响应时间,150ms检测没有滑动事件才会把点击事件传给子视图。这个delay属性设置成 YES也没用
按照 ![http://blog.sina.com.cn/s/blog_71715bf80101ie1e.html] 重写了UIScrollerView 设置表情scrollerview delaysContentTouches 属性为 YES; touchesShouldCancelInContentView 也设置了为YES.不行
把UIButton 换成 uiImage 加 tap手势,点击和滑动都可以。换成UIControl 也不行会立即触发TouchDown事件。
新建一个工程,在scrollerView上放上UIButton快速滑动,没问题。150ms的响应处理过程,存在。可能是工程插入的分类问题。
慢慢移除与UIscollerView 与 UIButton UIContol相关分类。最终问题定义在了DZNEmptyDataSet工具类上。升级版本后解决问题 DZNEmptyDataSet (1.8.1)
附:UIScrollerView 检测Touch原理:
当UIScrollView接收到一个touch时,它会在一段时间(好像是150ms)内监听该touch是否移动了,假如移动了(应该有一个移动范围),则取消将touch发送到其子视图(例如UIButton),UIScrollView自身接受该touch,进行滑动。
如果想UIScrollerView立即将事件传给UIButton.
UIScrollView中有一个属性叫delaysContentTouches
官方文档对它的解释是:If the value of this property is YES, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is NO , the scroll view immediately calls touchesShouldBegin:withEvent:inContentView:. The default value is YES.
意思就是设置为NO就不会存在那个150ms的判断时间了,直接执行后续操作.设置为NO后,UIButton立即响应并高亮。
设置完这个属性后,你会发现UIScrollView滑动不像以前那样了,假如touch down的那点落在UIButton上然后再滑动手指,UIScrollView不会滑动,但是UIButton仍然触发,当然,这样的结果也是应该的,你想想,设置delaysContentTouches为NO后,只要手指点在UIButton上,UIScrollView就会立即判定为这是点击UIButton,而不会再等待看手指是否移动来决定是否要滑动本身了。
有没有什么方法可以在touch到UIbutton上并滑动时不触发UIButton而让UIScrollView自己滑动呢,强大的iOS没有让你失望,
UIScrollView中有一个方法:touchesShouldCancelInContentView:
来看它的解释:The scroll view calls this method just after it starts sending tracking messages to the content view. If it receives NO from this method, it stops dragging and forwards the touch events to the content subview. The scroll view does not call this method if the value of the canCancelContentTouches property is NO.意思就是当UIScrollView将touch事件交给子view后,当手指发生滑动时,调用此方法,假如返回NO,则将touch事件交给子view,如果返回YES,则交给UIScrollView处理,产生滑动。
(但是前提是UIScrollView的canCancelContentTouches属性是YES才会调用这个方法,只要不是UIControll的子类,这个属性默认是YES。)所以只要重写UIScrollView的这个方法并返回YES就可以啦,到此问题就解决了。既能立即响应UIButton,也能自由滑动UIScrollView。
2016-10-11号最终发现是 DZNEmptyDataSet 这个空白页第三方库版本太低所致,pod 安装最新的版本后解决