在 UIScrollView 中使用 UITouch

Using UITouch inside a UIScrollView(在 UIScrollView 中使用 UITouch)
本文介绍了在 UIScrollView 中使用 UITouch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

只是在玩 SDK,我想知道 UITouch 事件是否可以在 UIScrollView 中工作.

Just toying with the SDK and I was wondering if possible a UITouch event can work inside a UIScrollView.

我已经设置了一个处理大型 UIView 的 UIScrollView,在 UIView 内部是一个 UIImageView,我设法让 UITouch 将 UIImageView 拖到 UIScrollView 之外,但在它内部没有注册事件.

I have setup a UIScrollView which handles a large UIView, inside the UIView is a UIImageView, I've managed to get the UITouch to drag the UIImageView outside of the UIScrollView but inside it's not registering the event.

我想我想要完成的是在大 UIView 周围拖动 UIImageView 而 UIScrollView 沿着图像移动,如果用户将其拖动到 UIImageView 开始拖动时的 POS 之外,如果这有意义吗?

I suppose what I was trying to accomplish was dragging the UIImageView around the large UIView whilst the UIScrollView moves along the image if the user drags it beyond the POS of when the UIView when the UIImageView began it's dragging, if that makes sense?

非常感谢

推荐答案

(如果我理解正确的话)

(If I understood the question correctly)

UIScrollView 拦截 touchMoved 事件,如果启用滚动,则不会将它们传播到其内容.因此,为了在我的应用程序中拖动 UIScrollView 内容,我做了以下技巧:

UIScrollView intercepts touchMoved events and does not propagate them to its contents if scrolling is enabled. So to do the dragging in the UIScrollView contents in my app I did the following trick:

touchesBegan:检查您是否触摸了可拖动"区域.如果是 - 禁用 UIScrollView 中的滚动.

touchesBegan: Check if you touch the "draggable" region. If YES - disable scrolling in UIScrollView.

touchesMoved:现在,当滚动被禁用时,您的内容视图会收到此事件,您可以相应地移动可拖动的 UIImageView.

touchesMoved: Now as scrolling is disabled your contents view receives this event and you can move your draggable UIImageView accordingly.

touchesEnded:在 UIScrolliew 中重新启用滚动.

touchesEnded: Reenable scrolling in UIScrolliew.

如果您想将视图拖到可见的 UIScrollView 区域之外,您可能还需要手动检查您是否靠近边界并手动调整内容偏移量(我自己没有尝试过,但我认为它应该可以工作).

If you want to drag the view outside of the visible UIScrollView area you may also need to check manually if you're near the boundaries and manually adjust contents offset (I didn't try this myself but I think it should work).

这篇关于在 UIScrollView 中使用 UITouch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

iOS UIScrollView Lazy Loading(iOS UIScrollView 延迟加载)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可缩放?)
How can i add more than 10 buttons on a navigationbar in iphone application development?(如何在 iphone 应用程序开发中的导航栏上添加 10 多个按钮?)
UIScrollView scrolling only with one finger(UIScrollView 只能用一根手指滚动)
UitextField resignFirstResponder does not work in scroll view(UitextField resignFirstResponder 在滚动视图中不起作用)
How to Stop a UIScrollView from Swallowing Touches(如何阻止 UIScrollView 吞下触摸)