2

我正在尝试更改 CALayer 的仿射变换,因此其中绘制的内容会变形。

首先,我在没有 CALayers 的情况下执行此操作,只是使用传递给 CGContextConcactCTM 的不同 CGAffineTransform 重新绘制。

这行得通,但速度不够快,所以我决定用 CALayer 来做,这样它就不会每次都重绘。它只是得到转变。

问题是设置 myLayer.affineTransform = myTransform; 似乎与使用 CGContextConcatCTM(myTransform); 重绘没有相同的效果;

我是 Objective-C 的新手,而且数学很差,所以我确定我做错了什么。但我看不出是什么。

谢谢。

4

1 回答 1

0

好吧,没关系,我发现了。

原来 myLayer.affineTransform 相对于图层中心进行变换,而 CGContextContactCTM 相对于原点进行变换。

所以我只是连接了另外两个转换:

    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));      
于 2011-09-26T20:18:32.020 回答