1

我不知道我做错了什么。多次缩放后,我的图像变小了?!?我按如下方式初始化变量:TOTAL_SCALE = 1.0; MIN_SCALE = 1.0;MAX_SCALE = 3.0;

这是我的pinchrecognizermethod:

- (void)pinchDetected:(UIPinchGestureRecognizer *)pinchRecognizer
{

CGFloat scale = pinchRecognizer.scale;
if (TOTAL_SCALE + (scale - 1.0) > MAX_SCALE) {
    scale = (MAX_SCALE - TOTAL_SCALE) + 1.0;
    TOTAL_SCALE = MAX_SCALE;
    imageView.transform = CGAffineTransformScale(imageView.transform, scale, scale);
}
else if(TOTAL_SCALE + (scale - 1.0) < MIN_SCALE){
    scale = (TOTAL_SCALE - MIN_SCALE) + 1.0;
    TOTAL_SCALE = MIN_SCALE;
    imageView.transform = CGAffineTransformScale(imageView.transform, scale, scale);
}
else{
    imageView.transform = CGAffineTransformScale(imageView.transform, scale, scale);
    TOTAL_SCALE += (scale - 1.0); 
}
pinchRecognizer.scale = 1.0;

}

有人能找到我的错误吗?预先感谢!

4

2 回答 2

1

想想当TOTALSCALE大于时这条线会产生什么MAXSCALE

scale = (MAX_SCALE - TOTAL_SCALE) + 1.0;

作为一般指南,您应该乘以比例,而不是添加比例。

于 2012-07-15T17:58:39.287 回答
1

正如 Mark Ransom 建议的那样,我改变了乘法的加法:

CGFloat scale = pinchRecognizer.scale;
if (TOTAL_SCALE*scale > MAX_SCALE) {
    scale = MAX_SCALE/TOTAL_SCALE;
    TOTAL_SCALE = MAX_SCALE;
    imageView.transform = CGAffineTransformScale(imageView.transform, scale, scale);
}
else if(TOTAL_SCALE*scale < MIN_SCALE){
    scale = MIN_SCALE/TOTAL_SCALE;
    TOTAL_SCALE = MIN_SCALE;
    imageView.transform = CGAffineTransformScale(imageView.transform, scale, scale);
}
else{
    imageView.transform = CGAffineTransformScale(imageView.transform, scale, scale);
    TOTAL_SCALE *= scale; 
}
于 2012-07-15T20:27:19.973 回答