Max/Min Scale of Pinch Zoom in UIPinchGestureRecognizer - iPhone iOS

后端 未结 10 1091
[愿得一人]
[愿得一人] 2020-11-29 17:29

How would I be able to limit the scale of the UIPinchGestureRecognizer to a min and max level? The scale property below seems to be relative to the last known scale (the de

10条回答
  •  [愿得一人]
    2020-11-29 18:06

    There isn't a way to limit the scale on a UIPinchGestureRecognizer. To limit the height in your code, you should be able to do something like this:

    CGFloat scale = 1.0 - (lastScale - pinchscale);
    CGRect bounds = [(UIPinchGestureRecognizer*)sender view].bounds;
    scale = MIN(scale, maximumHeight / CGRectGetHeight(bounds));
    scale = MAX(scale, minimumHeight / CGRectGetHeight(bounds));
    

    To limit width, change 'Height' to 'Width' in the last two lines.

提交回复
热议问题