我不知道我做错了什么。多次缩放后,我的图像变小了?!? 我将变量初始化如下: TOTAL_SCALE = 1.0; MIN_SCALE = 1.0; MAX_SCALE = 3.0;
这是我的pinchrecognizer方法:
- (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;
}
有人能找到我的错吗? 提前谢谢!
答案 0 :(得分:1)
当TOTALSCALE
大于MAXSCALE
时,请考虑此行产生的内容:
scale = (MAX_SCALE - TOTAL_SCALE) + 1.0;
作为一般指南,您应该将比例放大,而不是添加它们。
答案 1 :(得分: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;
}