NSView
All objects that inherit from NSView can render themselves on the screen. To be displayed, an NSView must be placed in an NSWindow. NSViews draw themselves by making calls to the Core Graphics (Quartz) programming interface.
Graphically, an NSView can be regarded as a framed canvas. The frame locates the NSView in its superview, defines its size, and clips drawing to its edges, while the canvas defines the NSView’s own internal coordinate system and hosts the actual drawing. The frame can be moved around, resized, and rotated in the superview, so that the NSView’s image moves with it. Similarly, the canvas can be shifted, stretched, and rotated, so that the drawn image moves within the frame.
NSView represents a context within which drawing can take place. This context has three components:
A rectangular frame within a window to which drawing is clipped
A coordinate system
The current graphics state
NSView draws itself as an indirect result of receiving the
display
message (or a variant of
display
); this message is sent explicitly or
through conditions that cause automatic display. The
display
message leads to the invocation of an
NSView’s drawRect:
method and the
drawRect:
methods of all subviews of that
NSView. The drawRect:
method should contain all
code needed to redraw the NSView completely.
An NSView object can be automatically displayed when:
Users scroll it (assuming it supports scrolling)
Users resize or expose the NSView’s window
The window receives a display message ...
Get Learning Cocoa 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.