CGContextConcatCTM 与 CALayer affineTransform
我正在尝试更改 CALayer 的仿射变换,以便其中绘制的内容变形。
首先,我在没有 CALayers 的情况下执行此操作,只是使用传递给 CGContextConcactCTM 的不同 CGAffineTransform 进行重绘。
这可行,但不够快,所以我决定使用 CALayer 来完成,这样就不会每次都重新绘制。它只是得到转变。
问题是设置 myLayer.affineTransform = myTransform;似乎与使用 CGContextConcatCTM(myTransform) 重绘效果不一样;
我是 Objective-C 的新手,数学也很差劲,所以我确信我做错了什么。但我看不到什么。
谢谢。
I'm trying to change the affine transform of a CALayer so what's drawn in it gets deformed.
First I was doing this without CALayers, just redrawing with a different CGAffineTransform passed to CGContextConcactCTM.
That worked, but it wasn't fast enough, so I decided to do it with CALayer so it won't get redrawn every time. It just get transformed.
The problem is that setting myLayer.affineTransform = myTransform; doesn't seem to have the same effect as redrawing with CGContextConcatCTM(myTransform);
I'm new to Objective-C and pretty lame at math, so I'm sure I'm doing something wrong. But I can't see what.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,没关系,我发现了。
结果 myLayer.affineTransform 相对于层的中心进行变换,而 CGContextContactCTM 相对于原点进行变换。
所以我只是连接了另外两个转换:
Ok, nevermind, I found out.
Turns out myLayer.affineTransform does the transform relative to the center of the layer where as CGContextContactCTM does it relative to the origin.
So I just concatenated 2 other transforms: