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

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

问题描述

在我的应用程序中,我有一个包含多个图像的scrollVIew。



而在滚动视图中,我有一个uiimageview。



我想从ScrollView中拖动任何图像,并将其放在滚动视图之外的uiimageview。



是否可能?



帮助和建议赞赏



提前感谢

解决方案

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



查看touchesBegan,touchesMoved等UIResponder中的委托方法。



一种方法是将子视图视图并实现touchesBegan,touchesMoved,并使用此imageview子类在滚动视图中显示图像。 / p>

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



然后在移动的触摸上,只需根据移动的触摸中的坐标重新调整此图像的框架以使图像跟随触摸。



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


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

and out of the scrollview i have one uiimageview.

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

is it possible?

help And suggestions are appreciated

Thanks in advance.

解决方案

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

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

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.

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

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