UIPanGestureRecognizer starting point is off

前端 未结 6 1485
庸人自扰
庸人自扰 2021-01-11 19:11

I have a UIView that has a UIPanGestureRecognizer attached to it the gesture is working fine except that the starting point is not where the pan first started it is usually

6条回答
  •  误落风尘
    2021-01-11 19:51

    To get around this you could try reseting the translation point when the gesture recognizer begins. For example, start your action method out like so:

    - (void)panGesture:(UIPanGestureRecognizer *)recognizer;
    {
        if ( recognizer.state == UIGestureRecognizerStateBegan )
        {
            CGPoint point = ...; // The view's initial origin.
            UIView *superview = [recognizer.view superview];
            [recognizer setTranslation:point inView:superview];
        }
    }
    

提交回复
热议问题