Introduction to View Programming Guide for Cocoa
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.
Who Should Read This Document
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 “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.
Organization of This Document
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
NSViewthat an application can subclass, and provides a dissection of a custom
“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 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
DotView is a simple application that implements a basic
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
NSViewimplementations 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
ColorSampler demonstrates using
lockFocusto read pixel colors from a view.
Reducer demonstrates use of Core Image, the
NSAnimationclass, and view drawing redirection. Includes a collapsible
NSViewsubclass that is Cocoa bindings-enabled.