Question

i don't know what i am doing wrong. After multiple scale my image gets smaller ?!? I initialize the variables as follows: TOTAL_SCALE = 1.0; MIN_SCALE = 1.0; MAX_SCALE = 3.0;

and this its my 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;

}

Can anybody find my mistake? Thank in advance!

Was it helpful?

Solution

Think about what this line produces when TOTALSCALE is greater than MAXSCALE:

scale = (MAX_SCALE - TOTAL_SCALE) + 1.0;

And as a general guide you should be multiplying scales, not adding them.

OTHER TIPS

I changed the addition to multiplication as Mark Ransom suggested:

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; 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top