开发者

Prevent pinchgesture zooming out of original frame

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, locati开发者_开发百科onInView.y / piece.bounds.size.height);
piece.center = locationInSuperview;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜