Graphics Programs Reference
In-Depth Information
Let's make the duration of this animation one second. That's enough time for the user to
see the spin but not so much time that they get bored waiting for it to complete.
Lastly, we need the values of the two keyframes: the
fromValue
and the
toValue
.
The documentation says that the
transform.rotation
is in radians, so that's how
we'll pass these values. A little geometry research tells us that no rotation is
0
radians and
a full rotation is
2 * PI
radians. When using a
CABasicAnimation
, if you do not
supply a
fromValue
, the animation assumes that
fromValue
is the current value of
that property. The default value of the
transform
property is the identity matrix - no
rotation. This means you only have to supply the final keyframe to this animation object.
In
TimeViewController.h
, declare a new method.
- (void)spinTimeLabel;
In
TimeViewController.m
, edit the method
showCurrentTime:
to call this
method.
- (IBAction)showCurrentTime:(id)sender
{
NSDate *now = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
[timeLabel setText:[formatter stringFromDate:now]];