Question

Is it possible to prevent UIPinchGestureRecognizer zooming out of the original frame? I know this can easily be done by using a UIScrollView, but that is not possible in this case.

I am currently using this to transform the view;

UIView *piece = gestureRecognizer.view;

CGPoint locationInView = [gestureRecognizer locationInView:piece];
CGPoint locationInSuperview = [gestureRecognizer locationInView:piece.superview];

[gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);
piece.layer.anchorPoint = CGPointMake(locationInView.x / piece.bounds.size.width, locationInView.y / piece.bounds.size.height);
piece.center = locationInSuperview;
Was it helpful?

Solution

The scale property will be less than 1 on a zoom out and greater than 1 on a zoom in, so simply check the scale when your recogniser fires and don't scale the view for a gesture scale of less than 1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top