美文网首页
拖动手势设置边界

拖动手势设置边界

作者: 开米肉丝酱 | 来源:发表于2021-04-08 15:51 被阅读0次
    - (void)handlePanGesture:(UIPanGestureRecognizer *)panGesture {
        
           CGPoint translation = [panGesture translationInView:panGesture.view.superview];
           CGFloat space = 20;
           // Figure out where the user is trying to drag the view.
           CGPoint newCenter = CGPointMake(panGesture.view.center.x+ translation.x,
                                           panGesture.view.center.y + translation.y);//    限制屏幕范围:
        
           newCenter.y = MAX(panGesture.view.frame.size.height/2, newCenter.y);
           newCenter.y = MIN(panGesture.view.superview.frame.size.height - panGesture.view.frame.size.height/2,  newCenter.y);
           newCenter.x = MAX(panGesture.view.frame.size.width/2+space, newCenter.x);
           newCenter.x = MIN(panGesture.view.superview.frame.size.width - panGesture.view.frame.size.width/2 - space,newCenter.x);
            panGesture.view.center = newCenter;
           [panGesture setTranslation:CGPointZero inView:panGesture.view.superview];
        
        // Don't need any logic for ended/failed/canceled states
    }
    

    相关文章

      网友评论

          本文标题:拖动手势设置边界

          本文链接:https://www.haomeiwen.com/subject/hnlvkltx.html