A Closer Look at the NSView Class
NSView is one of Cocoa’s most complicated classes. If you understand how it works, you can control the display of information on the computer’s screen and have it updated quickly and efficiently.
NSView Coordinate Systems
Each Cocoa NSView has its own coordinate system that can be rotated, scaled, or otherwise transformed from the coordinate system of its superview.
Each NSView also has the following two methods that describe its position in its window:
- - (NSRect)frame
Returns the NSView’s frame in the coordinate system of its superview
- - (NSRect)bounds
Returns the NSView’s frame (i.e., bounds) in its own coordinate system
When you change an NSView’s coordinate system, its
bounds
instance variable is automatically updated
to reflect the change, while its frame
instance
variable remains the same. The NSView class provides the following
methods for inspecting and changing an NSView’s
coordinate system:
- - (float)boundsRotation
Returns a floating-point number for the angle, in degrees, between an NSView’s coordinate system and the coordinate system of its superview.
- - (float)frameRotation
Returns the angle of the NSView’s frame relative to its superview’s coordinate system. A value of 0 means that the NSView has not been rotated (but its coordinate system may have been).
- - (BOOL)isRotatedFromBase
Returns TRUE if an NSView or any of its ancestors have been rotated from the window coordinate system.
- - (BOOL)isRotatedOrScaledFromBase
Returns TRUE ...
Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.