Combine longpress gesture and drag gesture together

后端 未结 5 767
执笔经年
执笔经年 2020-12-07 20:37

I\'m moving my views by

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveRight:)];
[panRecogn         


        
5条回答
  •  生来不讨喜
    2020-12-07 21:07

    You do not need to declare _priorPoint;

    In my case, i only want the view to move horizontally so i'm only changing the x coordinate.

    Here is my solution:

        if (longpressGestRec.state == UIGestureRecognizerStateChanged)
        {
            UIView *view = longpressGestRec.view;
    
            // Location of the touch within the view.
            CGPoint point = [longpressGestRec locationInView:view];
    
            // Calculate new X position based on the amount the gesture
            // has moved plus the size of the view we want to move.
            CGFloat newXLoc = (item.frame.origin.x + point.x) - (item.frame.size.width / 2);
            [item setFrame:CGRectMake(newXLoc,
                                      item.frame.origin.y,
                                      item.frame.size.width,
                                      item.frame.size.height)];
        }
    

提交回复
热议问题