Scaling CALayer up from bottom. (Not top)

112 views Asked by At

I have stumbled upon a problem that really shouldn't be too hard to figure out. However, after a lot of trial and error I have still not fount a solution. I have a CALayer created with CGRectMake(20, 20, 40, 40). I now want to scale this layer upwards by adding specific values to frame.size.height and frame.size.width, but when I do this, the layer scales downwards. I have tried modifying the anchorPoint, rotating the layer 180 degrees++, but no luck. Would love some input on this.

Thanks.

What I want vs What I get:

What I want What I get

1

There are 1 answers

0
Aaron Golden On BEST ANSWER

You just need to modify the y origin of your layer at the same time that you modify the height. I don't know exactly what your code looks like, but if you're taking the old frame and applying a constant change to the width and height, like this:

CGRect newFrame = oldFrame;
newFrame.size.width += kWidthChange;
newFrame.size.height += kHeightChange;
_myLayer.frame = newFrame;

then you just need one more line, like:

newFrame.origin.y -= kHeightChange;

before you reassign the layer's frame.

enter image description here