Search code examples
iosuigesturerecognizercgaffinetransformscale

UIRotationGestureRecognizer changes with CGAffineTransformMakeScale


A view is flipped using this:

self.transform = CGAffineTransformMakeScale(-1, 1);  // self is an UIView

To rotate this view:

-(void)handleRotate:(UIRotationGestureRecognizer *)recognizer
{
    recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
    recognizer.rotation = 0;
}

The issue is that after the view is flipped so is the rotation's direction. Any solution how to fix this?

Edit: My current solution is using a boolean and negate the recognizer.rotation value in handleRotate method. But I am still looking for the technical solution.


Solution

  • Have you try self.transform.a * recognizer.rotation ?
    If I understand correctly the AffineTransform, the X scaling is store at a.

    CGAffineTransform Reference Look for CGAffineTransformMakeScale and CGAffineTransformMake