iPhone OS Reference Library Apple Developer Connection spyglass button

Getting Started with Graphics & Animation

Overview

iPhone OS has several frameworks for graphics and animation:

You use UIKit to perform typical graphics operations in your user interface, such as drawing images, setting colors, and filling rectangles. It is also what you use for transformations (moving, scaling, rotating), to transition smoothly from one view (or screen) to another, and to animate content in a view or layer.

When you need more powerful 2D drawing capabilities, use the Core Graphics framework. It’s the workhorse for drawing vector graphics, lines, shapes, patterns, gradients, images, and even PDF documents. The higher-level frameworks, such as UIKit, use Core Graphics.

Core Animation is the programming interface that the UIKit framework uses for layering and transitions in its classes. Most of the time you won’t need to use Core Animation directly. Use it if your application requires fine-grained control over animations.

You use OpenGL ES to develop games or other applications that require the advanced graphics capabilities provided by the GPU.

The Basics

To understand the basics about how drawing works in iPhone OS, read the following chapters in iPhone Application Programming Guide:

Next Steps

To support graphics and animation in your iPhone application, you need to decide which frameworks to use for your particular needs. Then take a close look at a sample application that uses those frameworks, to see how to combine functions and methods from various frameworks to create a working application.

Deciding Which Frameworks to Use

In general, you should use the highest-level framework that meets the requirements of your application. Use lower-level frameworks only when you need more precise control or more powerful capabilities.

For information about the classes of the UIKit framework, see UIKit Framework Reference. For information about the classes of the Core Graphics and OpenGL ES frameworks, see Core Graphics Framework Reference and OpenGL ES Framework Reference. For information about how to incorporate animation into your applications, see "Graphics and Drawing" in iPhone Application Programming Guide.

Drawing Layered Content

To get started drawing layered content, make sure you are familiar with UIView Class Reference, especially the methods that manage the view hierarchy.

Next, open the Metronome sample application in Xcode. Take a look at the setupSubviews: method in the MetronomeView.m file to see how that application sets up subviews.

Animating

To get started animating content in your application, first read "Animating Views" in iPhone Application Programming Guide to find out which properties you can animate. Then look at "Applying Core Animation Effects" in iPhone Application Programming Guide.

Next, open the MoveMe sample application in Xcode. Look at the MoveMeView.m file, which contains several methods that animate views. The animateFirstTouchAtPoint:: and growAnimationDidStop:finished:context: methods show how to use the methods of the UIView class to animate views. The animatePlacardViewToCenter: method shows how to set up keyframe animation using Core Animation.

To get a more in-depth understanding of animation, read Core Animation Programming Guide.

Working With Images

To get started using images in your application, you’ll first want to look at UIImageView Class Reference and UIImage Class Reference. If you want to allow users to zoom images, you’ll also need to be familiar with UIScrollView Class Reference and UIScrollViewDelegate Protocol Reference.

Drawing Custom 2D Content

To get started drawing 2D content, first read "Drawing With Quartz and UI Kit" in iPhone Application Programming Guide. Then, take a look at CGContext Reference, which describes most of the functions you’ll use for drawing.

Next, examine the Finger Sketch sample code in Xcode. You’ll see how to set up Core Graphics, implement the drawRect: method, and draw content based on the user’s movements .

To get a deeper understanding of how drawing works, read Overview of Quartz 2D. To find out how to perform specific drawing tasks for example, creating a pattern, path, or gradient, read the appropriate chapter in Quartz 2D Programming Guide.

Drawing With OpenGL ES

To get started drawing with OpenGL ES, first read OpenGL ES Overview, provided by Khronos, the industry consortium that maintains the specifications for OpenGL ES.

Next, examine the GLSprite sample application in Xcode. You’ll see—in the EAGLView.m file—how to create a framebuffer object for OpenGL ES content.

To get a deeper understanding of how to best take advantage of OpenGL ES on the iPhone, read OpenGL ES Programming Guide for iPhone OS.



Last updated: 2009-10-19

Did this document help you? Yes It's good, but... Not helpful...