Who Should Read This Document
Organization of This Document
See Also
A view instance is responsible for drawing and responding to user actions in a rectangular region of a window. This document describes the role of views in a Cocoa application, how to manipulate views in a window, and how to create a custom view subclass for an application.
You should read this document to gain an understanding of working with views in a Cocoa application. You are expected to be familiar with Cocoa development, including the Objective-C language and memory management. The Cocoa Fundamentals Guide should be considered a prerequisite. The “Creating a Custom View” article expects that a developer is familiar with the Cocoa event model described in Cocoa Event-Handling Guide as well as the graphics drawing environment described in Cocoa Drawing Guide.
View Programming Guide for Cocoa consists of the following chapters:
“What Are Views?” describes the role of the view in Cocoa applications and an overview of the views provided by Cocoa.
“View Geometry” describes how views establish their base coordinate system.
“Working with the View Hierarchy” describes how an application inserts and removes views from the view hierarchy.
“Creating a Custom View” describes the various aspects of NSView
that an application can subclass, and provides a dissection of a custom NSView
subclass.
“Advanced Custom View Tasks” describes the advanced view subclass drawing tasks.
“Optimizing View Drawing” describes techniques to optimize view drawing.
There are other technologies, not fully covered in this document, that are fundamental to using views in your application. Refer to these documents for more details:
Cocoa Event-Handling Guide describes the event model used by Cocoa applications and explains how your objects can handle events and participate in the responder chain.
Cocoa Drawing Guide describes the basic methods used to draw curves, fill shapes, and modify the coordinate system.
Drag and Drop Programming Topics for Cocoa describes how to implement drag and drop in a view subclass.
There is also sample code available that provides detailed examples of view usage. The following sample code is installed in /Developer/Examples/Appkit
:
DotView is a simple application that implements a basic NSView
subclass.
Sketch is a scriptable graphics application. It provides a look at a complex view subclass than handles many types of events.
Worm provides three several different NSView
implementations that demonstrate techniques for improving a view's performance.
Additional sample code is available through Apple Developer Connection:
Bindings Joystick implements a “joystick” user interface item that illustrates a bindings-enabled subclass of NSView
.
ColorSampler demonstrates using lockFocus
to read pixel colors from a view.
Reducer demonstrates use of Core Image, the NSAnimation
class, and view drawing redirection. Includes a collapsible NSView
subclass that is Cocoa bindings-enabled.
© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-04-10)