UIScrollView 如何从其子视图中窃取触摸?

How does UIScrollView steal touches from its subviews?(UIScrollView 如何从其子视图中窃取触摸?)
本文介绍了UIScrollView 如何从其子视图中窃取触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我希望能够创建我自己的 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 如何从其子视图中窃取触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)