Graphics Reference
In-Depth Information
- (
void
)animate
{
//reset ball to top of screen
self
.
ballView
.
center
=
CGPointMake
(
150
,
32
);
//configure the animation
self
.duration =
1.0
;
self
.timeOffset =
0.0
;
self
.fromValue = [
NSValue
valueWithCGPoint
:
CGPointMake
(
150
,
32
)];
self
.toValue = [
NSValue
valueWithCGPoint
:
CGPointMake
(
150
,
268
)];
//stop the timer if it's already running
[
self
.timer
invalidate
];
//start the timer
self
.timer = [
NSTimer
scheduledTimerWithTimeInterval
:
1
/
60.0
target
:
self
selector
:
@selector
(step:)
userInfo
:
nil
repeats
:
YES
];
}
- (
void
)step:(
NSTimer
*)step
{
//update time offset
self
.timeOffset =
MIN
(
self
.timeOffset +
1
/
60.0
,
self
.duration);
//get normalized time offset (in range 0 - 1)
float
time =
self
.timeOffset /
self
.duration;
//apply easing
time =
bounceEaseOut
(time);
//interpolate position
id
position = [
self
interpolateFromValue
:
self
.fromValue
toValue
:
self
.toValue
time
:time];
//move ball view to new position
self
.ballView.
center
= [position
CGPointValue
];
//stop the timer if we've reached the end of the animation
if
(
self
.timeOffset >=
self
.duration)
{
[
self
.timer
invalidate
];