Mac Developer Library

Developer

Foundation Framework Reference NSAffineTransform Class Reference

Options
Deployment Target:

On This Page
Language:

NSAffineTransform

The NSAffineTransform class provides methods for creating, concatenating, and applying affine transformations. More...

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.0 and later.
  • Creates and returns a new NSAffineTransform object initialized to the identity matrix.

    Declaration

    Objective-C

    + (NSAffineTransform *)transform

    Return Value

    A new identity transform object. This matrix transforms any point to the same point.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

  • Initializes the receiver’s matrix using another transform object and returns the receiver.

    Declaration

    Swift

    convenience init(transform aTransform: NSAffineTransform)

    Objective-C

    - (instancetype)initWithTransform:(NSAffineTransform *)aTransform

    Parameters

    aTransform

    The transform object whose matrix values should be copied to this object.

    Return Value

    A new transform object initialized with the matrix values of aTransform.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    See Also

    + transform

  • Applies a rotation factor (measured in degrees) to the receiver’s transformation matrix.

    Declaration

    Swift

    func rotateByDegrees(_ angle: CGFloat)

    Objective-C

    - (void)rotateByDegrees:(CGFloat)angle

    Parameters

    angle

    The rotation angle, measured in degrees.

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Applies a rotation factor (measured in radians) to the receiver’s transformation matrix.

    Declaration

    Swift

    func rotateByRadians(_ angle: CGFloat)

    Objective-C

    - (void)rotateByRadians:(CGFloat)angle

    Parameters

    angle

    The rotation angle, measured in radians.

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Applies the specified scaling factor along both x and y axes to the receiver’s transformation matrix.

    Declaration

    Swift

    func scaleBy(_ scale: CGFloat)

    Objective-C

    - (void)scaleBy:(CGFloat)scale

    Parameters

    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.

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Applies scaling factors to each axis of the receiver’s transformation matrix.

    Declaration

    Swift

    func scaleXBy(_ scaleX: CGFloat, yBy scaleY: CGFloat)

    Objective-C

    - (void)scaleXBy:(CGFloat)scaleX yBy:(CGFloat)scaleY

    Parameters

    scaleX

    The scaling factor to apply to the x axis.

    scaleY

    The scaling factor to apply to the y axis.

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Applies the specified translation factors to the receiver’s transformation matrix.

    Declaration

    Swift

    func translateXBy(_ deltaX: CGFloat, yBy deltaY: CGFloat)

    Objective-C

    - (void)translateXBy:(CGFloat)deltaX yBy:(CGFloat)deltaY

    Parameters

    deltaX

    The number of units to move along the x axis.

    deltaY

    The number of units to move along the y axis.

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Appends the specified matrix to the receiver’s matrix.

    Declaration

    Swift

    func appendTransform(_ aTransform: NSAffineTransform)

    Objective-C

    - (void)appendTransform:(NSAffineTransform *)aTransform

    Parameters

    aTransform

    The matrix to append to the receiver.

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Prepends the specified matrix to the receiver’s matrix.

    Declaration

    Swift

    func prependTransform(_ aTransform: NSAffineTransform)

    Objective-C

    - (void)prependTransform:(NSAffineTransform *)aTransform

    Parameters

    aTransform

    The matrix to prepend to the receiver.

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Replaces the receiver’s matrix with its inverse matrix.

    Declaration

    Swift

    func invert()

    Objective-C

    - (void)invert

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Applies the receiver’s transform to the specified NSPoint data type and returns the results.

    Declaration

    Swift

    func transformPoint(_ aPoint: NSPoint) -> NSPoint

    Objective-C

    - (NSPoint)transformPoint:(NSPoint)aPoint

    Parameters

    aPoint

    The point in the current coordinate system to which you want to apply the matrix.

    Return Value

    The resulting point after applying the receiver's transformations.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Applies the receiver’s transform to the specified NSSize data type and returns the results.

    Declaration

    Swift

    func transformSize(_ aSize: NSSize) -> NSSize

    Objective-C

    - (NSSize)transformSize:(NSSize)aSize

    Parameters

    aSize

    The size data to which you want to apply the matrix.

    Return Value

    The resulting size after applying the receiver's transformations.

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Sets the current transformation matrix to the receiver’s transformation matrix.

    Declaration

    Swift

    func set()

    Objective-C

    - (void)set

    Discussion

    The current transformation is stored in the current graphics context and is applied to subsequent drawing operations. You should use this method sparingly because it removes the existing transformation matrix, which is an accumulation of transformation matrices for the screen, window, and any superviews. Instead use the concat method to add this transformation matrix to the current transformation matrix.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Appends the receiver’s matrix to the current transformation matrix stored in the current graphics context, replacing the current transformation matrix with the result.

    Declaration

    Swift

    func concat()

    Objective-C

    - (void)concat

    Discussion

    Concatenation is performed by matrix multiplication—see Manipulating Transform Values.

    If this method is invoked from within an NSViewdrawRect: method, then the current transformation matrix is an accumulation of the screen, window, and any superview’s transformation matrices. Invoking this method defines a new user coordinate system whose coordinates are mapped into the former coordinate system according to the receiver’s transformation matrix. To undo the concatenation, you must invert the receiver’s matrix and invoke this method again.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – set
    - invert

Data Types

  • This type defines the three-by-three matrix that performs an affine transform between two coordinate systems.

    Declaration

    Swift

    struct NSAffineTransformStruct { var m11: CGFloat var m12: CGFloat var m21: CGFloat var m22: CGFloat var tX: CGFloat var tY: CGFloat }

    Objective-C

    typedef struct _NSAffineTransformStruct { CGFloat m11, m12, m21, m22; CGFloat tX, tY; } NSAffineTransformStruct;

    Discussion

    For more details, see Cocoa Drawing Guide.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.