CALayer 锚点无法按预期与 CGAffineTransform 一起工作
我有一个 CALayer,包含几个子层(CATextLayers)。 我在 CALayer 上应用一些常用手势(缩放、平移)的转换。 一切都工作得很好,除了缩放(缩放)是向左下角而不是屏幕中心进行的。
我在 CoreAnimation 编程指南中找到了一些信息,并尝试将锚点设置为屏幕中心,以便每个转换都会朝着该锚点完成......但它似乎没有按预期工作。
这是我的代码:
在 init 函数内部:
_layerMgr = [[CALayer alloc] init];
_layerMgr.frame = [[UIScreen mainScreen] bounds];
_layerMgr.anchorPoint = CGPointMake(0.5, 0.5);
在手势事件上完成:
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);
也许问题来自我的子视图?我已经使用 addSubView 方法添加了它们......没什么花哨的......
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.anchorPoint = 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在“您的”_layerMgr.transform 上进行转换,而不是创建一个新的:
例如:
try to transform on "YOUR" _layerMgr.transform instead of creating a new one:
for example: