Ios – Scale with CGAffineTransform and set the anchor


If I understand correctly scaling a UIView with CGAffineTransform anchors the transformation to its center.

In particular:

self.frame = CGRectMake(0,0,100,100);
self.transform = CGAffineTransformMakeScale(2, 2);
NSLog(@"%f;%f;%f;%f", self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height); 



How do you create a CGAffineTransform scale that uses a specific anchor point (say 0;0)?

Best Solution


Scale and then translate?

Something like :

CGAffineTransform t = CGAffineTransformMakeScale(2, 2);
t = CGAffineTransformTranslate(t, width/2, height/2);
self.transform = t;


Set the anchor point (which is probably what you want really)

[self layer].anchorPoint = CGPointMake(0.0f, 0.0f);
self.transform = CGAffineTransformMakeScale(2, 2);


Set the center again to make sure it's in the same place?

CGPoint center =;
self.transform = CGAffineTransformMakeScale(2, 2); = center;