0

I have an image grid that I am zooming in and zooming out on click of the image. All is working fine, but I am having trouble controlling the rotation of the CGAffineTransform. I thought I could pass in the angle to control how my rotation is determined, but when I do so, the transform will not zoom in and I am left zoomed out.
I feel that I have missed the proper implementation of this along somewhere during creating my routine, so if anyone can point out where I went wrong I would appreciate it Here is my code

     float angle =  -1.661799;

     if(status == 0){
             [UIView animateWithDuration:1.5f delay:0.0f
               options:UIViewAnimationOptionCurveEaseIn animations:^{
                  CGAffineTransform totalTransform =
                  CGAffineTransformMakeTranslation(-middleX  , -middleY );
                  totalTransform = CGAffineTransformScale(totalTransform, 3.5f, 3.5f);
                  totalTransform = CGAffineTransformTranslate(totalTransform, middleX , middleY );
                  //totalTransform = CGAffineTransformMakeRotation(angle);
                 [self.view setTransform:totalTransform];
             }completion:^(BOOL finished) {
             }];
            status++;
     }else{
            [UIView animateWithDuration:1.3f delay:0.0f 
               options:UIViewAnimationOptionCurveEaseIn animations:^{

                  CGAffineTransform tr = CGAffineTransformMakeScale(1.00 ,1.00);
                  [self.view setTransform:tr];
                }completion:^(BOOL finished) {

                  [UIView animateWithDuration:1.3f delay:0.0f 
                  options:UIViewAnimationOptionCurveEaseIn animations:^{
                        CGAffineTransform totalTransform =
                        CGAffineTransformMakeTranslation(-middleX  , -middleY );
                        totalTransform = CGAffineTransformScale(totalTransform, 3.5f, 3.5f);
                        totalTransform = CGAffineTransformTranslate(totalTransform, middleX , middleY );
                        //totalTransform = CGAffineTransformMakeRotation(angle);
                        [self.view setTransform:totalTransform];
                   }completion:^(BOOL finished) {}];

               }];
               status = 0;
      }

1 Answer 1

1

This is an old question--but in case anyone comes back to it:

When you are doing a series of transforms, you need to use the right call. There are two calls for each type of transform (rotate, translate, scale). One is used for combinations of transforms, and the other is for making a new transform.

The first call can be a "Make" call. The subsequent calls need to be the non-make variety.

"Make" call, which generates a transformation matrix:

CGAffineTransformMakeRotation(angle)

non-make call, which modifies an existing transformation matrix:

CGAffineTransformRotate(existingMatrix, angle)

so, from your code:

CGAffineTransform totalTransform = 
      CGAffineTransformMakeTranslation(-middleX  , -middleY );
totalTransform = CGAffineTransformScale(totalTransform, 3.5f, 3.5f);
totalTransform = CGAffineTransformTranslate(totalTransform, middleX , middleY );
totalTransform = CGAffineTransformMakeRotation(angle);

Your first call created a matrix, as is appropriate. However your rotation call (the 4th call) should be:

 totalTransform = CGAffineTransformRotate(totalTransform, angle);

Otherwise, as you noticed, you discard all the transformations before that call, and only get rotation, in this case, or whatever your last transformation would be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.