Graphics Reference
In-Depth Information
CGPoint to = [toValue CGPointValue ];
CGPoint result = CGPointMake ( interpolate (from. x , to. x , time),
interpolate (from. y , to. y , time));
return [ NSValue valueWithCGPoint :result];
}
}
//provide safe default implementation
return (time < 0.5 )? fromValue: toValue;
}
- ( void )animate
{
//reset ball to top of screen
self . ballView . center = CGPointMake ( 150 , 32 );
//set up animation parameters
NSValue *fromValue = [ NSValue valueWithCGPoint : CGPointMake ( 150 , 32 )];
NSValue *toValue = [ NSValue valueWithCGPoint : CGPointMake ( 150 , 268 )];
CFTimeInterval duration = 1.0 ;
//generate keyframes
NSInt eger numFrames = duration * 60 ;
NSMutableArray *frames = [ NSMutableArray array ];
for ( int i = 0 ; i < numFrames; i++)
{
float time = 1 /( float )numFrames * i;
[frames addObject :[ self interpolateFromValue :fromValue
toValue :toValue
time :time]];
}
//create keyframe animation
CAKeyframeAnimation *animation = [ CAKeyframeAnimation animation ];
animation. keyPath = @"position" ;
animation. duration = 1.0 ;
animation. delegate = self ;
animation. values = frames;
//apply animation
[ self . ballView . layer addAnimation :animation forKey : nil ];
}
Search WWH ::




Custom Search