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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中设置滚动视图内容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自动滚动)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延迟加载)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模拟器上运行时,使用 iOS 6.0 SDK 并为 iOS 5 Target 构建会导致 UIScrollView setMinimumZoomScale 失败) -
Create partial-screen UIPageViewController programmatically(以编程方式创建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可缩放?)