在UIScrollView中使用UITouch [英] Using UITouch inside a UIScrollView

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

问题描述



我设置了一个UIScrollView处理一个大的UIView,内部UIView是一个UIImageView,我设法得到的UITouch拖动UIImageView外面的UIScrollView,但它里面没有注册的事件。



我想我的试图完成是拖动UIImageView在大UIView周围,而UIScrollView移动沿着图像,如果用户拖动它超过UIView在UIImageView开始拖动时的UIView的POS,如果这是有意义的?



非常感谢

解决方案

(如果我正确理解了这个问题)



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



touchesBegan:检查是否触摸draggable地区。如果是 - 禁用滚动UIScrollView。



touchesMoved:现在,由于滚动已禁用,您的内容视图将接收此事件,因此您可以相应地移动可拖动的UIImageView。



touchesEnded:在UIScrollView中重新启用滚动。



如果要将视图拖动到可见的UIScrollView区域,你可能还需要手动检查,如果你在边界附近,手动调整内容偏移(我没有尝试这个自己,但我认为它应该工作)。


Just toying with the SDK and I was wondering if possible a UITouch event can work inside a 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.

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?

Many thanks

解决方案

(If I understood the question correctly)

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: Check if you touch the "draggable" region. If YES - disable scrolling in UIScrollView.

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

touchesEnded: Reenable scrolling in UIScrolliew.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆