IOS仿桌面拖动桌面图标

手势拖动

UIPanGestureRecognizer * panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self
                                                                                                    action:@selector(doMoveAction:)];

核心部分

拖到到前面还是后面的判断

                    Boolean preMove =true;
                    //判断前后移动四种情况
                    //(ex<startPoint.x && ey<startPoint.y)||(ex>startPoint.x && ey<startPoint.y) ||(ex==startPoint.x && ey<startPoint.y)
|| (ey==startPoint.y && ex <startPoint.x)
//偏差5都认为相等 CGFloat diff =10; if ((startPoint.x-ex>diff && startPoint.y-ey>diff)||(ex>(startPoint.x+diff) && (ey+diff)<startPoint.y)
||(fabs(ex-startPoint.x)<=diff && (ey+diff)<startPoint.y)|| (fabs(ey-startPoint.y)<=diff && (ex+diff) <startPoint.x) )

 

 

 

完整代码

posted on 2020-06-05 17:52  Honey_Badger  阅读(577)  评论(0编辑  收藏  举报

导航

github