如何防止传递给UIView的superview的触摸事件? [英] how to prevent a touch event passed to a UIView's superview?

查看:255
本文介绍了如何防止传递给UIView的superview的触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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的superview的触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆