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

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

问题描述

我在一个 UIViewController 中有一个水平滚动视图,其中我有很多小尺寸的图像。我将图像保存在scrollview中,因为图像更多,因此用户可以水平滚动并选择图像。但是,问题是,我必须选择一个图像并拖放到 UIViewController 视图。但是,由于图像在scrollview中,因此将图像拖放到 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?

推荐答案


Hi Getsy,

Hi Getsy,

我不会直接提供你的代码,如何管理这个。

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:启用滚动视图在 touchesEnded:

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天全站免登陆