Transformations
NSAffineTransform
provides an
interface
for defining and applying affine transforms to various parts of the
graphics system, such as view coordinate systems, individual Bezier
paths or NSPoints. An affine transform is a type of mapping
between coordinate systems in which a shape’s
parallel lines are preserved, but not necessarily the length of line
segments or the angles between lines. Out-of-the-box,
NSAffineTransform
is capable
of rotating,
translating, and
scaling.
To create an affine transform, use the transform convenience constructor. The following example shows how you can create an affine transform object and make a rotation transformation:
NSAffineTransform * at = [NSAffineTransform transform]; [at rotateByDegrees:77];
To transform a Bezier path using this affine transform object, invoke
transformBezierPath:
NSBezierPath *newPath = [at transformBezierPath:bp];
This method takes the Bezier path to transform as a parameter and
returns a new Bezier path that is the transformation of the original.
Using a method of NSBezierPath, you can transform
a path directly without having a new object returned. The method is
transformUsingAffineTransform:, and is used in the
following way:
[bp transformUsingAffineTransform:rat];
Here is how you transform an NSPoint structure:
at = [NSAffineTransform transform]; [at translateXBy:100 yBy:50]; NSPoint point = NSMakePoint( 0, 0 ); NSPoint newPoint = [at transformPoint:point];
To transform an NSSize, do the following:
at = [NSAffineTransform ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access