When I scale a layer, the result always has origin set at CGPoint(0,0). What is the best way to make sure after the scale, the layer is still center in its super layer?
[CATransaction begin];
[CATransaction setAnimationDuration: 0];
[CATransaction setDisableActions: TRUE];
self.maskLayer.transform = CATransform3DScale(CATransform3DIdentity, .8, .8,1);
self.maskLayer.position = CGPointMake(kScreenWidth/2,kScreenHeight/2);
[CATransaction commit];
You need to set the layer's anchorPoint to be its center:
self.maskLayer.anchorPoint = CGPointMake(0.5, 0.5);
and then set its position to the centre of its superLayer
self.maskLayer.position = (CGPoint){CGRectGetMidX(superLayer.bounds), CGRectGetMidY(superLayer.bounds)};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With