Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSAffineTransform.h |
Related sample code |
The NSAffineTransform
class provides methods for creating, concatenating, and applying affine transformations.
A transformation specifies how points in one coordinate system are transformed to points in another coordinate system. An affine transformation is a special type of transformation that preserves parallel lines in a path but does not necessarily preserve lengths or angles. Scaling, rotation, and translation are the most commonly used manipulations supported by affine transforms, but shearing is also possible.
Note: In Mac OS X v10.3 and earlier the NSAffineTransform
class was declared and implemented entirely in the Application Kit framework. As of Mac OS X v10.4 the NSAffineTransform
class has been split across the Foundation Kit and Application Kit frameworks.
Methods for applying affine transformations to the current graphics context and a method for applying an affine transformation to an NSBezierPath
object are described in NSAffineTransform Additions in the Application Kit.
– rotateByDegrees:
– rotateByRadians:
– scaleBy:
– scaleXBy:yBy:
– translateXBy:yBy:
– appendTransform:
– prependTransform:
– invert
Creates and returns a new NSAffineTransform
object initialized to the identity matrix.
+ (NSAffineTransform *)transform
A new identity transform object. This matrix transforms any point to the same point.
NSAffineTransform.h
Appends the specified matrix to the receiver’s matrix.
- (void)appendTransform:(NSAffineTransform *)aTransform
The matrix to append to the receiver.
This method multiplies the receiver's matrix by the matrix in aTransform and replaces the receiver's matrix with the results. This type of operation is the same as applying the transformations in the receiver followed by the transformations in aTransform.
NSAffineTransform.h
Initializes the receiver’s matrix using another transform object and returns the receiver.
- (id)initWithTransform:(NSAffineTransform *)aTransform
The transform object whose matrix values should be copied to this object.
A new transform object initialized with the matrix values of aTransform.
NSAffineTransform.h
Replaces the receiver’s matrix with its inverse matrix.
- (void)invert
Inverse matrices are useful for undoing the effects of a matrix. If a previous point (x,y) was transformed to (x’,y’), inverting the matrix and applying it to point (x’,y’) yields the point (x,y).
You can also use inverse matrices in conjunction with the concat
method to remove the effects of concatenating the matrix to the current transformation matrix of the current graphic context.
NSAffineTransform.h
Prepends the specified matrix to the receiver’s matrix.
- (void)prependTransform:(NSAffineTransform *)aTransform
The matrix to prepend to the receiver.
This method multiplies the matrix in aTransform by the receiver’s matrix and replaces the receiver’s matrix with the result. This type of operation is the same as applying the transformations in aTransform followed by the transformations in the receiver.
NSAffineTransform.h
Applies a rotation factor (measured in degrees) to the receiver’s transformation matrix.
- (void)rotateByDegrees:(CGFloat)angle
The rotation angle, measured in degrees.
After invoking this method, applying the receiver’s matrix turns the axes counterclockwise about the current origin by angle degrees, in addition to performing all previous transformations.
NSAffineTransform.h
Applies a rotation factor (measured in radians) to the receiver’s transformation matrix.
- (void)rotateByRadians:(CGFloat)angle
The rotation angle, measured in radians.
After invoking this method, applying the receiver’s matrix turns the axes counterclockwise about the current origin by angle radians, in addition to performing all previous transformations.
NSAffineTransform.h
Applies the specified scaling factor along both x and y axes to the receiver’s transformation matrix.
- (void)scaleBy:(CGFloat)scale
The scaling factor to apply to both axes. Specifying a negative value has the effect of inverting the direction of the axes in addition to scaling them. A scaling factor of 1.0 scales the content to exactly the same size.
After invoking this method, applying the receiver’s matrix modifies the unit lengths along the current x and y axes by a factor of scale, in addition to performing all previous transformations.
NSAffineTransform.h
Applies scaling factors to each axis of the receiver’s transformation matrix.
- (void)scaleXBy:(CGFloat)scaleX yBy:(CGFloat)scaleY
The scaling factor to apply to the x axis.
The scaling factor to apply to the y axis.
After invoking this method, applying the receiver’s matrix modifies the unit length on the x axis by a factor of scaleX and the y axis by a factor of scaleY, in addition to performing all previous transformations. A value of 1.0 for either axis scales the content on that axis to the same size.
NSAffineTransform.h
Replaces the receiver’s transformation matrix with the specified values.
- (void)setTransformStruct:(NSAffineTransformStruct)aTransformStruct
The structure containing the six transform values you want the receiver to use.
The matrix is of the form shown in “Manipulating Transform Values”, and the six-element structure defined by the NSAffineTransformStruct
structure is of the form:
{m11, m12, m21, m22, tX, tY} |
The NSAffineTransformStruct
structure is an alternate representation of a transformation matrix that can be used to specify matrix values directly.
NSAffineTransform.h
Applies the receiver’s transform to the specified NSPoint
data type and returns the results.
- (NSPoint)transformPoint:(NSPoint)aPoint
The point in the current coordinate system to which you want to apply the matrix.
The resulting point after applying the receiver's transformations.
NSAffineTransform.h
Applies the receiver’s transform to the specified NSSize
data type and returns the results.
- (NSSize)transformSize:(NSSize)aSize
The size data to which you want to apply the matrix.
The resulting size after applying the receiver's transformations.
This method applies the current rotation and scaling factors to aSize; it does not apply translation factors. You can think of this method as transforming a vector whose origin is (0, 0) and whose end point is specified by the value in aSize. After the rotation and scaling factors are applied, this method effectively returns the end point of the new vector.
This method is useful for transforming delta or distance values when you need to take scaling and rotation factors into account.
NSAffineTransform.h
Returns the matrix coefficients stored in the receiver’s matrix.
- (NSAffineTransformStruct)transformStruct
The structure containing the receiver's six matrix values.
The matrix is of the form shown in “Manipulating Transform Values”, and the six-element structure defined by the NSAffineTransformStruct
structure is of the form:
{m11, m12, m21, m22, tX, tY} |
The NSAffineTransformStruct
structure is an alternate representation of a transformation matrix that can be used to specify matrix values directly.
NSAffineTransform.h
Applies the specified translation factors to the receiver’s transformation matrix.
- (void)translateXBy:(CGFloat)deltaX yBy:(CGFloat)deltaY
The number of units to move along the x axis.
The number of units to move along the y axis.
Subsequent transformations cause coordinates to be shifted by deltaX units along the x axis and by deltaY units along the y axis. Translation factors do not affect NSSize
values, which specify a differential between points.
NSAffineTransform.h
This type defines the three-by-three matrix that performs an affine transform between two coordinate systems.
typedef struct _NSAffineTransformStruct { float m11, m12, m21, m22; float tX, tY; } NSAffineTransformStruct;
m11 , m12, m21, m22
Elements of a two-by-two matrix for rotation, scale, and shear transformations.
tX, tY
x and y translation elements
For more details, see Cocoa Drawing Guide.
NSAffineTransform.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-01-15)