CGContextConcatCTM vs CALayer affineTransform
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.
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:
CGPoint center;
center.x = capa.bounds.origin.x + capa.bounds.size.width/2;
center.y = capa.bounds.origin.y + capa.bounds.size.height/2;
CGAffineTransform trf1 = CGAffineTransformMakeTranslation(center.x, center.y);
CGAffineTransform trf2 = CGAffineTransformMakeTranslation(-center.x, -center.y);
capa.affineTransform = CGAffineTransformConcat(trf1, CGAffineTransformConcat(mat, trf2));
精彩评论