处理子UIScrollView中的触摸事件 [英] Handling touch events within a child UIScrollView
问题描述
我在UIScrollView中显示一系列图像。我非常想复制Photos应用程序。
I'm displaying a series of images in a UIScrollView. I pretty much want to replicate the Photos application.
我当前的架构是:
My current architecture is:
所以我在父UIScrollView中基本上有一行UIScrollViews。
So I basically have a row of UIScrollViews within a parent UIScrollView.
父UIScrollView启用了分页,因此我可以在页面之间滚动而没有任何问题。
The parent UIScrollView has paging enabled so I can scroll from page to page without any problems.
问题是如何无缝地围绕放大的图像平移。我已经覆盖 viewForZoomingInScrollView
方法,以便在用户进/出时返回相应的UIImageView。我已经覆盖了 scrollViewDidEndZooming
方法,将父视图的 canCancelContentTouches
属性设置为 NO
如果缩放比例大于1.
The problem is how to seamlessly pan around a zoomed-in image. I have overridden the viewForZoomingInScrollView
method to return the appropriate UIImageView when the user pinches in/out. I have overriden the scrollViewDidEndZooming
method to set the parent view's canCancelContentTouches
property to NO
if the zoom scale is greater than 1.
因此用户可以平移图像。但是,在将触摸事件发送到子视图之前,他们必须将手指放下一会儿才能超过父滚动视图的小延迟。此外,一旦用户在一个图像中平移,当用户到达当前图像的边界时,下一个/上一个图像不会进入可视区域。
So users are able to pan around an image. However, they must hold their finger down for a moment to get past the small delay the parent scroll view has before sending touch events down to the subviews. Also, once the user is panning in one image, the next/prev images do not enter the viewable area when the user has reached the border of the current image.
任何想法?
谢谢。
推荐答案
我必须做类似的事情设置,但我基本上自定义写了整个事情。我不确定当你到达边缘时,你是如何解决从子UIScrollView'切换'触摸事件到父UISscrollView的问题。您可以尝试在父UIScrollView中覆盖UITouchesBegan:withEvent:并直接转储给子级。祝你好运!
I had to do a similar setup, but I basically custom wrote the whole thing. I'm not sure how you're going to get around the problem of 'handing off' touch events from the child UIScrollView to the parent UISscrollView when you reach the edge. You might try overriding UITouchesBegan:withEvent: in your parent UIScrollView, and dumping directly to the child. Good luck!
这篇关于处理子UIScrollView中的触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!