CGAffineTransfrom可以有两种不同的组合方式:CGAffineTransformTranslate/Rotate/Scale 和 CGAffineTransformConcate。在使用中要注意二者的区别。
简单的说, 下面两组代码的结果是等效的:
CGAffineTransfrom combinedTrans = CGAffineTransfromMakeTranslate(transX, transY);
combinedTrans = CGAffineTransformRotate(combinedTrans, angel);
combinedTrans = CGAffineTransformScale(combinedTrans, scaleX, scaleY);
translatedPoint = CGPointApplyTransform(point, trans);
和
CGAffineTransform trans = CGAffineTransformMakeTranslate(transX, transY);
CGAffineTransform rotation = CGAffineTransformMakeRotation(angel);
CGAffineTransform scale = CGAffineTransformMakeRotation(scaleX, scaleY);
CGAffineTransform combinedTrans = CGAffineTransformConcat(scale, rotation);
combinedTrans = CGAffineTransformConcat(combinedTrans, trans);
translatedPoint = CGPointApplyTransform(point, combinedTrans);
上面的代码其实是先缩放,再旋转,再平移,而不是反过来。
再写程序的时候一定要注意,否则结果会很另人疑惑。