开发者

CALayer anchorPoint doesn't work as expected with CGAffineTransform

开发者 https://www.devze.com 2023-04-10 09:27 出处:网络
I have a CALayer, containing few sublayers (CATextLayers). I\'m applying transformations on the CALayer on some usual gestures (zoom, pan).

I have a CALayer, containing few sublayers (CATextLayers). I'm applying transformations on the CALayer on some usual gestures (zoom, pan). Everything works perfectly fine except that the scaling (zoom) is done towards the bottom left corner instead of the center of the screen.

I found some info in the CoreAnimation programming guide and I tried setting the anchor point to the center of my screen so that every transformation would be done towards that anchor....But it doesn't seem to be working as expected.

Here's my code :

// inside the init function :

_layerMgr = [[CALayer alloc] init];

_layerMgr.frame = [[UIScreen mainScreen] bounds];

_layerMgr.an开发者_开发知识库chorPoint = CGPointMake(0.5, 0.5);

// done on gesture events :

CGAffineTransform tt = CGAffineTransformMakeTranslation( offset.x, -offset.y);

CGAffineTransform st = CGAffineTransformMakeScale( scale ,scale );

CGAffineTransform rt = CGAffineTransformMakeRotation(rotation);

transform = CGAffineTransformConcat( tt, CGAffineTransformConcat( st,rt) );

_layerMgr.transform = CATransform3DMakeAffineTransform(_transform);

Maybe the problem comes from my subviews ? I've added them using the addSubView method...nothing fancy...


try to transform on "YOUR" _layerMgr.transform instead of creating a new one:

for example:

[_layerMgr setTransform:CGAffineTransformScale (_layerMgr.transform, 2, 2)];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号