iosiphonedelayuigesturerecognizeruipangesturerecognizer

Why is there a delay when moving object using UIPanGestureRecognizer?


I'm moving UIView object using UIPanGestureRecognizer — how much I drag my finger on screen, that much I move the view in the same direction (only in X - left or right, Y is not changing). It works fine, but with (very noticeable) delay.

Here is the method that handles the UIPanGestureRecognizer event:

-(void)movePages:(UIPanGestureRecognizer *)sender
{
    if (switchingMode == 1) {
        if ([sender state] == UIGestureRecognizerStateBegan) {
            fingerStartPosition = [sender locationInView:self.view].x;
            viewStartPosition = [[viewControllers objectAtIndex:activeViewControllerIndex] view].center;
        }
        [[[[viewControllers objectAtIndex:activeViewControllerIndex] view] layer] setPosition:CGPointMake(viewStartPosition.x - (fingerStartPosition - [sender locationInView:self.view].x) , viewStartPosition.y)];            
    }
}

I've tried to set position of the view using its layer, I've also tried setting the frame, using animations with different durations, but everything behaved the same. Any idea why this delay occurs ?


Solution

  • Use a UILongPressGestureRecognizer and set the minimumPressDuration to 0.0. This recognizes instantly and you get all the same updates including the UIGestureRecognizerStateChanged with the updated location.