UIPinchGestureRecognizer 中捏合缩放的最大/最小比例 - iPhone iOS [英] Max/Min Scale of Pinch Zoom in UIPinchGestureRecognizer - iPhone iOS

查看:35
本文介绍了UIPinchGestureRecognizer 中捏合缩放的最大/最小比例 - iPhone iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何才能将 UIPinchGestureRecognizer 的比例限制为最小和最大级别?下面的 scale 属性似乎与最后一个已知比例(上一个状态的增量)有关,我不知道如何设置缩放对象的大小/高度的限制.

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 delta from last state) and I can't figure out how to set a limit to the size/heigh of the object being zoomed.

-(void)scale:(id)sender {

[self.view bringSubviewToFront:[(UIPinchGestureRecognizer*)sender view]];

if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
    lastScale = 1.0;
    return;
}

CGFloat pinchscale = [(UIPinchGestureRecognizer*)sender scale];
CGFloat scale = 1.0 - (lastScale - pinchscale);
CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
CGAffineTransform holderTransform = holderView.transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
[[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform];

lastScale = [(UIPinchGestureRecognizer*)sender scale];

}

推荐答案

没有办法限制 UIPinchGestureRecognizer 的比例.要限制代码中的高度,您应该能够执行以下操作:

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.

这篇关于UIPinchGestureRecognizer 中捏合缩放的最大/最小比例 - iPhone iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆