Graphics Reference
In-Depth Information
Figure 5.4 The effect of multiple affine transforms applied in sequence
There are a few things worth noting about Figure 5.4: The image has been moved to the
right, but not as far as we specified (200 points), and it has also moved down instead of just
sideways. The reason for this is that when you apply transforms sequentially in this way,
the previous transforms affect the subsequent ones. The 200-point translation to the right
has been rotated by 30 degrees and scaled by 50%, so it has actually become a translation
diagonally downward by 100 points.
This means that the order in which you apply transforms affects the result; a translation
followed by a rotation is not the same as a rotation followed by a translation.
The Shear Transform
Because Core Graphics provides functions to calculate the correct values for the transform
matrix for you, it's rare that you need to set the fields of a CGAffineTransform
directly. One such circumstance is when you want to create a shear transform, for which
Core Graphics provides no built-in function.
The shear transform is a fourth type of affine transform. It is less commonly used than
translation, rotation, and scaling (which is probably why Core Graphics has no built-in
function for it), but it can still sometimes be useful. Its effect is probably best illustrated
with a picture (see Figure 5.5). For want of a better term, it makes the layer “slanty.”
Listing 5.3 shows the code for the shear transform function.
Search WWH ::




Custom Search