@ Interface firstviewcontroller ()
@ Property (nonatomic, assign) bool isplay;
@ End
@ Implementation firstviewcontroller
@ Synthesize isplay;
-(Void) viewdidload
{
[Superviewdidload];
Isplay = no;
// Rounded corner
Self. imgview. layer. cornerradius = 150.0/2.0;
Self. imgview. layer. maskstobounds = yes;
// Add an animation
Cabasicanimation * monkeyanimation = [cabasicanimationanimationwithkeypath: @ "transform. Rotation. Z"];
Monkeyanimation. tovalue = [nsnumbernumberwithfloat: 2.0 * m_pi];
Monkeyanimation. Duration = 1.5f;
Monkeyanimation. timingfunction = [camediatimingfunctionfunctionwithname: kcamediatimingfunctionlinear];
Monkeyanimation. Cumulative = no;
Monkeyanimation. removedoncompletion = no; // No remove
Monkeyanimation. repeatcount = flt_max;
[Self. imgview. layeraddanimation: monkeyanimation forkey: @ "animatedkey"];
[Self. imgviewstopanimating];
// Load the animation but do not play the animation
Self. imgview. layer. speed = 0.2;
}
-(Void) didreceivememorywarning
{
[Superdidreceivememorywarning];
// Dispose of any resources that can be recreated.
}
// Start the animation
-(Ibaction) startanimate :( ID) sender {
If (! Isplay ){
Isplay = yes;
Self. imgview. layer. speed = 1.0;
Self. imgview. layer. begintime = 0.0;
Cftimeinterval pausedtime = [self. imgview. layertimeoffset];
Cftimeinterval timesincepause = [self. imgview. layerconverttime: cacurrentmediatime () fromlayer: Nil]-pausedtime;
Self. imgview. layer. begintime = timesincepause;
}
}
// Stop the animation and save the current angle
-(Ibaction) stioanimate :( ID) sender {
If (isplay ){
Isplay = no;
Cftimeinterval pausedtime = [self. imgview. layerconverttime: cacurrentmediatime () fromlayer: Nil];
Self. imgview. layer. speed = 0.0;
Self. imgview. layer. timeoffset = pausedtime;
}
}
@ End