如何将uiimage从滚动视图拖动到iphone sdk中的另一个uiimageview [英] how to drag an uiimage from scrollview to another uiimageview in iphone sdk

查看:22
本文介绍了如何将uiimage从滚动视图拖动到iphone sdk中的另一个uiimageview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个包含多个图像的滚动视图.

In My Application,i am having one scrollVIew containing multiple images.

在滚动视图之外,我有一个 uiimageview.

and out of the scrollview i have one uiimageview.

我想将任何图像从 ScrollView 拖放到滚动视图之外的 uiimageview 上.

i want to Drag any image from ScrollView and drop it on uiimageview which is out of the scrollview.

有可能吗?

感谢帮助和建议

提前致谢.

推荐答案

是的,这应该是可能的,你需要直接实现触摸/拖动事件.

Yes this should be possible, you will need to implement the touch/drag events directly.

查看 UIResponder 中的 touchesBegan、touchesMoved 等委托方法.

Check out the touchesBegan, touchesMoved etc. delegate methods in UIResponder.

一种方法是子类化 imageview 并在其中实现 touchesBegan、touchesMoved,然后使用这个 imageview 子类在滚动视图中显示图像.

One approach would be to subclass imageview and implement touchesBegan, touchesMoved in it, and use this imageview subclass to display your images in the scroll view.

在 touchesBegan 创建一个新的图像视图并将其添加到外部视图并将其图像设置为与滚动视图中的图像相同.您需要将其直接覆盖在滚动视图中的源图像上,因此将其框架原点调整为相对于外部视图,您将需要使用滚动视图原点以及内容视图大小和内容内源图像视图的偏移量视图以重新计算外部视图中的新原点.

On the touchesBegan create a new image view and add it to the outer view and set its image to be the same as the one in the scroll view. You need to overlay it directly over your source image in the scroll view so adjust its frame origin to be relative to the outer view you will need to use the scrollview origin and also the content view size and offset of the source image view inside the content view in order to recalculate the new origin in the outer view.

然后在触摸移动时,只需根据触摸移动的坐标重新调整此图像的框架,以便图像跟随触摸.

Then on the touches moved, simply readjust the frame of this image in accordance with the coordinates from the touches moved so that the image follows the touch.

对目标图像视图的框架进行边界检查 - 一旦用户将其拖动到此边界,使目标图像视图图像与被拖动视图中的图像相同,并从包含视图中删除拖动的图像并释放它.

Do a boundary check against the frame of your target imageview - once the user drags it into this boundary, make that target imageviews image the same as the image in the view being dragged and remove the dragged image from the containing view and release it.

这篇关于如何将uiimage从滚动视图拖动到iphone sdk中的另一个uiimageview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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