Search code examples
iphoneobjective-cuigesturerecognizercgaffinetransformuipangesturerecognizer

CGAffineTransformMakeTranslation Movement


I am using CGAffineTransformMakeTranslation with UIPanGestureRecognizer to pan a UIView.

Does CGAffineTransformMakeTranslation take delta x and delta y or the absolute value of the new position? Here's what I have:

- (void)swipeDetected:(UIPanGestureRecognizer *)recognizer
{

    CGPoint newTranslation = [recognizer translationInView:self.view];
    self.navController.view.transform = CGAffineTransformMakeTranslation(newTranslation.x, 0);
    .....
}

This works from left to right but not from right to left. I'm pretty sure "translation" means delta x and delta y and not absolute value.

Any suggestions?

Thanks


Solution

  • Setting the transform is an immediate operation as it is just matrix multiplication of the view's location.

    If you need to revert back from your current position, you can save the transform to an ivar, and use an inverse transform, ie:

    _currentTransform = CGAffineTransformMakeTranslation(newTranslation.x, 0);

    and later:

    CGAffineTransform inverse = CGAffineTransformInvert(_currentTransform);

    If you want to remove all transforms you can do self.transform = CGAffineTransformIdentity

    Hope this helps!