问题描述
我制作了一个程序,其中包含可以拖动以在屏幕上移动的图片.我也使用了 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 的超级视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


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