Core Graphics
A framework that supports the graphics context (more on this later), loading im-
ages, drawing images, and so on.
Core Animation
A framework that, as its name implies, facilitates animations in iOS.
Basic Concepts for Adapting to Different Screen Sizes
When drawing on a screen, one of the most important concepts to grasp is the relation
between points and pixels. I’m sure you’re familiar with pixels, but what are points?
They’re the device-independent counterpart of pixels. For instance, compare the
iPhone 3GS to the iPhone 4. Both devices have 3.5-inch displays. However, the number
of pixels that iPhone 3GS can draw in portrait mode is 320×480. The same screen size
on the iPhone 4 is capable of drawing twice as many, or 640×960, pixels in portrait
mode.
Now imagine you are writing an iPhone app that has only one screen, and that you are
simply filling the whole screen with the color green. Imagine that you naïvely specify a
rectangular area of 320×480 pixels. When iPhone 3GS users run your app, they will be
quite happy because “it does what it says it does”—fill the entire screen with the color
green. iPhone 4 users, on the other hand, will be quite unhappy: what they will see is
quite different, as shown in Figure 1.
To remedy this problem, Apple introduced device-independent drawing methods to
help developers focus on how their shapes and graphics have to appear on a device
instead of worrying about the screen sizes and resolutions of different devices that run
the same code. To fix the issue we saw in Figure 1, the developer of the app can simply
use the relevant APIs to specify the green rectangle in points instead of pixels. That will
allow the same code to run on the iPhone 3GS and the iPhone 4, ensuring that the
screen on the iPhone 4 will be filled with the rectangle. For this reason, many of the
methods that you will see in this book will rely on points (or as Apple calls them, logical
points) instead of pixels.
The origin point of the screen on an iOS device is the top-left corner.
Screens whose drawing origin is on the top-left corner are also referred
to as Upper Left Origin, or ULO, screens. This means that point (0, 0)
is the topmost and the leftmost point on the screen, and that positive
values of the x axis extend towards the right, while positive values of
the y axis extend towards the bottom. In other words, an x position of
20 is further right on the screen than a position of 10 is. On the y axis,
point 20 is further down than point 10.
2 | Graphics and Animations