0

I have an image view that I want to pinch to rescale without keeping the aspect ratio. In order to do this, I thought it might be feasible to either:

  1. Use two pinch gesture recognisers, one that stretches horizontally, one that does so vertically.
  2. Use one pinch recogniser but apply the two transforms one after the other.

Here's my pinch handling function:

- (void) pinch:(UIPinchGestureRecognizer *)recognizer {
    static CGRect initialBounds;

    if (recognizer.state == UIGestureRecognizerStateBegan)
    {
        initialBounds = imageView.bounds;
    }
    CGFloat factor = [(UIPinchGestureRecognizer *)recognizer scale];

    //scale horizontally
    CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity, 
                                                     factor-(1.0-factor), 1.0);
    imageView.bounds = CGRectApplyAffineTransform(initialBounds, zt);

    //now scale vertically
    zt = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, factor);
    imageView.bounds = CGRectApplyAffineTransform(initialBounds, zt);
    return;
}

For some reason, the transform is only being done vertically (last one). I tried changing the first parameter of the second CGRectApplyAffineTransform to imageView.bounds, but it still didn't work.

Can anyone please tell me where I am going wrong?

Also, when using two pinch gesture recognisers, the same thing happens - only one of them actually gets recognised.

Thanks!

Sorin Cioban
  • 2,237
  • 6
  • 30
  • 36

1 Answers1

0

Your second one is starting with a CGAffineTransformIdentity. Instead, pass in the zt.

tobinjim
  • 1,862
  • 2
  • 19
  • 31