如何防止触摸事件传递给 UIView 的超级视图?

how to prevent a touch event passed to a UIView#39;s superview?(如何防止触摸事件传递给 UIView 的超级视图?)
本文介绍了如何防止触摸事件传递给 UIView 的超级视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我制作了一个程序,其中包含可以拖动以在屏幕上移动的图片.我也使用了 UIScrollView,因为空间比窗口大.我将 UIView 子类化为图片视图,以在此类中显示图片并处理触摸.图片视图作为子视图添加到滚动视图.但现在我有一个问题:当我拖动图片时,scrollView 与图片一起移动.我想知道是否有办法消耗图片类中的触摸以防止它们传递给超级视图.

I've made a program which contains pictures that can be dragged to move on the screen. also I used UIScrollView since the space is larger than the window. I subclassed UIView as a pictures view to display the picture and handle touches in this class. picture views are added as subviews to the scrollView. but now I have a problem: when I drag the picture, the scrollView moves together with the picture. I'm wondering if there is a way to consume the touches in the picture class to prevent them from passing to superview.

推荐答案

你应该把你的代码放在 UIView 的 "touchesMoved:withEvent:" 方法中.如果你的 View 会自己处理这个事件,那么它不应该冒泡到 superview

You should to put your code in "touchesMoved:withEvent:" method of your UIView. If your View will handle this event by yourself, then it should not bubble to superview

这篇关于如何防止触摸事件传递给 UIView 的超级视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

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]如何禁用自动旋转?)