Graphics Reference
In-Depth Information
Figure 3.6 The clock face, with misaligned hands
A solution that would work is to add additional transparent space at the bottom of all the
images, but that makes the images larger than they need to be, and they will consume more
memory as a result. That's not very elegant.
A better solution is to make use of the anchorPoint property. Let's add some additional
lines of code to our -viewDidLoad method to offset the anchorPoint for each of our
clock hands (see Listing 3.2). Figure 3.7 shows the correctly aligned hands.
Listing 3.2 Clock with Adjusted anchorPoint Values
- ( void )viewDidLoad
{
[ super viewDidLoad ];
//adjust anchor points
self . secondHand . layer . anchorPoint = CGPointMake ( 0.5f , 0.9f );
self . minuteHand . layer . anchorPoint = CGPointMake ( 0.5f , 0.9f );
self . hourHand . layer . anchorPoint = CGPointMake ( 0.5f , 0.9f );
//start timer
...
}
Search WWH ::




Custom Search