使用平移手势交换图像 [英] swapping images using pan gesture
问题描述
我在主视图中添加了多个 UIImageView
,每个 UIImageView
都显示在其自己的父<$ c中$ c> UIView 为了裁剪目的,每个 UIImageView
也附加到 PanGestureRecognizer
。
I have multiple UIImageView
added into the main view, each UIImageView
is displayed in its own parent UIView
for cropping purpose, each UIImageView
is also attached to a PanGestureRecognizer
.
我很好奇如何实现pan gesturerecgonizer并通过拖动一个图像(A)将鼠标悬停在另一个图像上(B)并保持,然后允许图像交换图像A和B将被交换(因此A现在显示在旧B的UIView中)。
I am curious on how to implement both pan gesturerecgonizer and also allow image swap by dragging one image (A) to hover over the other image (B) and hold, then the image A and B will be swapped (so A is now displayed in old B's UIView).
这就像刚刚实施的iPhoto应用程序。
This is something like the iPhoto app just implemented.
任何想法?
推荐答案
-
实现平移手势
Implement the pan gesture
在处理平移手势的方法中,检查
两个imageview的帧是否通过相交CGRectIntersectsRect 。In the method which handles the pan gesture check if the frames of two imageview's intersect by using CGRectIntersectsRect.
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded) { if(CGRectIntersectsRect(frame1,frame2)) // Swap both the imageview's }
这篇关于使用平移手势交换图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!