Graphics Reference
In-Depth Information
When you are manipulating transforms, it is often useful to be able to create a transform
that does nothing at all—the CGAffineTransform equivalent of zero or nil. In the
world of matrices, such a value is known as the identity matrix , and Core Graphics provides
a convenient constant for this:
CGAffineTransformIdentity
Finally, if you ever want to combine two existing transform matrices, you can use the
following function, which creates a new CGAffineTransform matrix from two existing
ones:
CGAffineTransformConcat( CGAffineTransform t1, CGAffineTransform t2);
Let's use these functions in combination to build up a more complex transform. We'll start
by applying a scale factor of 50%, then a 30-degree rotation, and finally a translation of 200
points to the right (see Listing 5.2). Figure 5.4 shows the result of applying these transforms
to our layer.
Listing 5.2 Creating a Compound Transform Using Several Functions
- ( void )viewDidLoad
{
[ super viewDidLoad];
//create a new transform
CGAffineTransform transform = CGAffineTransformIdentity;
//scale by 50%
transform = CGAffineTransformScale(transform, 0.5 , 0.5 );
//rotate by 30 degrees
transform = CGAffineTransformRotate (transform, M_PI / 180.0 * 30.0 );
//translate by 200 points
transform = CGAffineTransformTranslate(transform, 200 , 0 );
//apply transform to layer
self .layerView.layer.affineTransform = transform;
}
Search WWH ::




Custom Search