iPhone/iOS:如何为 Scrollview 的子视图实现拖放? [英] iPhone/iOS: How to implement Drag and Drop for subviews of a Scrollview?

查看:26
本文介绍了iPhone/iOS:如何为 Scrollview 的子视图实现拖放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIViewController 中有一个水平滚动视图,其中有许多小尺寸的图像.我将图像保留在滚动视图中,因为图像更多,因此用户可以水平滚动并选择图像.但是,问题是,我必须选择一个图像并将其拖放到该 UIViewController 视图中.但是,由于图像在滚动视图中,因此无法将图像拖放到 UIViewcontroller 的视图中,也无法检测到触摸事件.请注意:如果我没有滚动视图,但只是将图像也保留在 UIViewcontroller 的视图本身中,将图像拖放到同一屏幕上,效果很好好.

I am having an horizontal scrollview in an UIViewController, where i have many images in small sizes. I am keeping the images in scrollview because the images are more, so user can scroll horizontally and choose images. But, the problem is, i have to select an image and drag and drop to that UIViewController view. But, since the images are in scrollview, drag and drop images into UIViewcontroller's view is not working, not detecting the touch events too. Please NOTE: If i don't have scrollview but just keeping the images also into UIViewcontroller's view itself, drag and drop the images on the same screen, is working very well.

当我需要滚动视图和拖放图像时,我该如何解决这个问题,请提供任何建议/帮助?

How can I resolve this when I need to have scrollview and drag and drop images, any advice/help please?

推荐答案

盖西,

我不会直接向您提供代码,但会告诉您如何管理它.

I am not going to provide you code directly but give idea how to manage this.

您可以通过这种方式进行管理,当您当时在 scrollView 中触摸您的对象时,或者当您通过拖动来移动该对象时,通过 myScroll.scrollEnabled = NO; 禁用滚动

然后在 endTouch 上时,您可以通过 myScroll.scrollEnabled = YES; 启用滚动,因此您可以管理您的对象在滚动中移动,希望您有逻辑.

You can manage this way, When you get touch on your object in scrollView at that time or when you move that object by draging at that time disable scroll by myScroll.scrollEnabled = NO;

Then When on endTouch you can enable Scroll by myScroll.scrollEnabled = YES; So by this you can manage you object moving in scroll hope you got logic.

这里是演示代码:使用 ScrollView 拖放.在 touchesMoved: 上的 Disabling 滚动视图和 touchesEnded: 上的 Enabling 滚动视图具有相同的逻辑.

Here is the demo code : Drag and Drop with ScrollView. which has same logic of Disabling scroll view on touchesMoved: and Enabling scroll view on touchesEnded:.

这篇关于iPhone/iOS:如何为 Scrollview 的子视图实现拖放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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