Using UITouch inside a UIScrollView(在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 UIScrollView 中使用 UITouch
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01