swapping images using pan gesture

爱⌒轻易说出口 提交于 2019-12-04 05:35:55

问题


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.

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).

This is something like the iPhoto app just implemented.

Any ideas?


回答1:


  • Implement the pan gesture

  • 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
    }
    


来源:https://stackoverflow.com/questions/11794731/swapping-images-using-pan-gesture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!