简体   繁体   English

如何防止UIScrollView拦截其自身视图层次结构之外的触摸?

[英]How do I prevent UIScrollView from intercepting touches outside of it's own view hierarchy?

My understanding of touch handling is that when a view is touched, if it itself doesn't handle touches, it 'hands' the touches up the view hierarchy until they are either handled, or you're at the top and they're discarded. 我对触摸处理的理解是,当触摸视图时,如果它本身不处理触摸,它会“触摸”视图层次结构,直到它们被处理,或者你处于顶部而它们被丢弃。 (In essence, it's recursion; it hands the touches up to their subview, at which point the same 'upward' direction functions are called to pass it upward). (实质上,它是递归;它将触摸交给他们的子视图,此时调用相同的'向上'方向函数将其向上传递)。

I'm in an odd situation where a UIScrollView -- which SHOULD intercept and handle any and all touches from it's children -- appears to be intercepting the touches of a UIImageView placed 'on top' of it. 我在一个奇怪的情况下,UIScrollView - 它应该拦截并处理来自它的孩子的任何和所有触摸 - 似乎正在拦截放置在它顶部的UIImageView的触摸。 Remove the scroll view, and touches work properly. 删除滚动视图,并触摸正常工作。 The problem is, the UIImageView in question is NOT a child of the UIScrollView; 问题是,有问题的UIImageView不是UIScrollView的子代; it's a sibling. 这是一个兄弟姐妹。

So my question becomes twofold: first, how do I stop it from 'stealing' these touches, and two, how can it be stealing them in the first place? 所以我的问题变成了两个方面:首先,我如何阻止它“偷”这些触摸,第二,它怎么能在一开始就偷它们?

Try setting userInteractionEnabled to YES on the UIImageView. 尝试在UIImageView上将userInteractionEnabled设置为YES。 If userInteractionEnabled is set to NO (which should be the default for a UIImageView), then touches would be passed down to the object below it -- the UIScrollView. 如果userInteractionEnabled设置为NO(应该是UIImageView的默认值),则触摸将传递给它下面的对象--UIScrollView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM