Graphics Reference
In-Depth Information
Figure 10.4
A custom easing function, suitable for a clock tick
Listing 10.5
The Clock Program with Custom Easing Function Added
- (
void
)setAngle:(
CGFloat
)angle
forHand:(
UIView
*)handView
animated:(
BOOL
)animated
{
//generate transform
CATransform3D
transform =
CATransform3DMakeRotation
(angle,
0
,
0
,
1
);
if
(animated)
{
//create transform animation
CABasicAnimation
*animation = [
CABasicAnimation
animation
];
animation.
keyPath
=
@"transform"
;
animation.
fromValue
=
[handView.
layer
.
presentationLayer valueForKey
:
@"transform"
];
animation.
toValue
= [
NSValue
valueWithCATransform3D
:transform];
animation.
duration
=
0.5
;
animation.
delegate
=
self
;
animation.
timingFunction
=
[
CAMediaTimingFunction
functionWithControlPoints
:
1
:
0
:
0.75
:
1
];
//apply animation
handView.
layer
.
transform
= transform;
[handView.
layer
addAnimation
:animation
forKey
:
nil
];