CTM转换与iOS中的仿射变换(用于翻译,旋转,缩放) [英] CTM transforms vs Affine Transforms in iOS (for translate, rotate, scale)

查看:604
本文介绍了CTM转换与iOS中的仿射变换(用于翻译,旋转,缩放)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通读转换文档。其中似乎有两种方法可以进行转换。一种方法是修改当前转换矩阵(CTM)。它有如下方法:

I read through the Transforms documentation in the Quartz 2D Programming Guide. In it there appears to be two ways to make transformations. One way is through modifying the Current Transformation Matrix (CTM). It has methods like the following:


  • CGContextTranslateCTM

  • CGContextRotateCTM

  • CGContextScaleCTM

  • CGContextTranslateCTM
  • CGContextRotateCTM
  • CGContextScaleCTM

另一种方法是使用仿射变换。它有如下方法:

The other way is to use Affine transforms. It has methods like the following:


  • CGAffineTransformTranslate

  • CGAffineTransformRotate

  • CGAffineTransformScale

  • CGAffineTransformTranslate
  • CGAffineTransformRotate
  • CGAffineTransformScale

文档状态


Quartz中可用的仿射变换函数在矩阵,而不是CTM。

The affine transform functions available in Quartz operate on matrices, not on the CTM.

但我不明白这实际上是如何影响我的。看起来我可以使用任何一种方法得到相同的结果。我何时应该使用CTM变换?何时应该使用仿射变换?

But I don't understand how that affects me practically. It seems like I can get the same result using either method. When should I use the CTM transforms and when should I use the Affine transforms?

推荐答案

CTM是当前的变换矩阵和CTM方法将对当前矩阵进行操作。

CTM is a current transformation matrix and the CTM methods will make operations on the current matrix.

其他版本的函数将在给定矩阵上进行转换,这意味着您需要指定要转换的矩阵。在您这样做之后,您可以以任何方式将变换应用于CTM或将其用于任何其他目的。

The other version of functions will make the transformation on a given matrix which means you need to specify which matrix you are trying to transform. After you did so you may apply the transform to the CTM any way you want or use it for any other purpose.

例如,这两个操作将是相同的:

For instance these 2 operations would be the same:

CGContextTranslateCTM(context, 10, 10);

仿射:

CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, 10, 10);
CGContextConcatCTM(context, transform);

正如你所看到的那样,第一个或多或少只是方便,所以你不需要写这么多代码。

As you can see the first one is more or less just a convenience so you do not need to write so much code.

这篇关于CTM转换与iOS中的仿射变换(用于翻译,旋转,缩放)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆