Graphics Reference
In-Depth Information
So, why would we want to change the anchorPoint ? We can already place the frame
wherever we want, so doesn't changing the anchorPoint just cause confusion? To
illustrate why this might be useful, let's try a practical example. Let's build an analog clock
face with moving hour, minute, and second hands.
The face and hands are constructed using four images (see Figure 3.4). To keep things
simple, we'll load and display these images in the traditional way, using four separate
UIImageView instances (although we could do this using regular views by setting their
backing layer contents images).
Figure 3.4 The four images that make up the clock face and hands
The clock components are arranged in Interface Builder (see Figure 3.5). The image views
are nested inside another container view and have both autoresizing and autolayout
disabled. This is because autoresizing acts on the view frame , and as demonstrated in
Figure 3.2, the frame changes when the view is rotated, which will lead to layout glitches
if a rotated view's frame is resized.
We'll use an NSTimer to update our clock, and make use of the view's transform
property to rotate the hands. (If you are not familiar with that property, don't worry; we
cover it in Chapter 5, “Transforms.”) Listing 3.1 shows the code for our clock.
Search WWH ::




Custom Search