Objective-C Convert to X and Y

I was looking into CGAffineTransforms and was wondering if there is a way to make your look and scale up the x, y coordinates. I have scaled down some of the scaling with a function:

       CGAffineTransformMakeScale(4.00 ,4.00);

      

However, I don't know how to relate the scaling to the possible x, y coordinate. Has anyone ever done something like this? Perhaps I am wrong about using these functions?

       -(void)buttonSelected:(id)sender
       {
          UIButton *b = sender;
          CGPoint location = b.frame.origin;

          [UIView animateWithDuration:1.3f delay:0.0f options:UIViewAnimationCurveEaseIn animations:^{
               CGAffineTransform totalTransform =
               CGAffineTransformMakeTranslation(-location.x  , -location.y );
               totalTransform = CGAffineTransformScale(totalTransform, 4.0f, 4.0f);
               totalTransform = CGAffineTransformTranslate(totalTransform, location.x , location.y );
               [self.view setTransform:totalTransform];
           }completion:^(BOOL finished) {
           }];

       }

      

+3


source to share


1 answer


You either built the transformation by following three steps:

  • the move point that you want to scale to the center of the layer;
  • scale;
  • move the object back to bring the original center back to the center.

For example,



// to use a point that is (109, 63) from the centre as the point to scale around
CGAffineTransform totalTransform =
                  CGAffineTransformMakeTranslation(-109.0f, -63.0f);
totalTransform = CGAffineTransformScale(totalTransform, 4.0f, 4.0f);
totalTransform = CGAffineTransformTranslate(totalTransform, 109.0f, 63.0f);

      

Or perhaps more simply adjust view.layer

anchorPoint

. The resulting second idea is that when you adjust the anchor point first, you get an immediate transformation, because all other positioning refers to the center.

+5


source







All Articles