Friday, 15 August 2014

ios - UIImage view resets after animation is called -



ios - UIImage view resets after animation is called -

im new core animation. every time phone call animation image moves location top left of screen, moves, goes original location. how create image move 50 units left, stop, repeat if button pressed again. code:

-(ibaction)preform:(id)sender{ cgpoint point = cgpointmake(50, 50); cabasicanimation *anim = [cabasicanimation animationwithkeypath:@"position"]; anim.fromvalue = [nsvalue valuewithcgpoint:point]; anim.tovalue = [nsvalue valuewithcgpoint:cgpointmake(point.x + 50, point.y)]; anim.duration = 1.5f; anim.repeatcount =1; anim.removedoncompletion = yes; anim.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctioneasein]; [imview.layer addanimation:anim forkey:@"position"]; }

for case, can skip heavy ca machinery , utilize block animations

// image @ starting position [uiview animatewithduration:1.5 animations:^{ cgrect newframe = cgrectoffset(imview.frame, 50, 0); imview.frame = newframe; }];

but, if want know how handle "snap back" correctly, check this url.

ios cocoa-touch core-animation caanimation

No comments:

Post a Comment