问题描述
我希望能够创建我自己的 UIView 容器子类,它可以在子视图之前先对触摸做出反应.这很棘手,因为通常子视图在超级视图之前接收触摸事件(通过 touchesBegan: 等).UIScrollView 是如何反转这个的?
I'd like to be able to create my own container subclasses of UIView which can react first to touches, before their subviews. This is tricky because normally a subview receives touch events (via touchesBegan: etc) before superviews. How does UIScrollView reverse this?
明确地说,我不是询问 UIScrollView 的行为如何.我了解它的作用,以及您通常如何使用它.我在问我如何才能干净地实现我自己的版本 - 不是因为我想要,而是因为我正在尝试构建利用类似行为的可重用容器视图.
To be clear, I am not asking how UIScrollView behaves. I understand what it does, and how you would normally use it. I'm asking about how I could cleanly implement my own version of this -- not because I want to, but because I'm trying to build reusable container views that take advantage of similar behavior.
推荐答案
您可以在 UIView 子类中实现 hitTest:withEvent: 方法.
You can implement hitTest:withEvent: method in your UIView subclass.
调用此方法来检查必须接收触摸事件的子视图,因此您可以在它实际发生之前在那里执行一些操作.您还可以更改必须接收事件的子视图.
This method gets called to check what subview must receive the touch event, so you can perform some action there before it actually happens. You can also change subview that must receive event.
这篇关于UIScrollView 如何从其子视图中窃取触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)