ios - CAKeyFrameAnimation: Where/How to set the final position/scale? -
i trying create button shrink/expand upon touch using code below.
- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *mytouch = [touches anyobject]; uiview *view = [mytouch view]; view.transform = cgaffinetransformmakescale(0.7, 0.7);<--is correct?? cakeyframeanimation *scale = [cakeyframeanimation animationwithkeypath:@"transform.scale"]; scale.duration = 0.8; scale.values = @[@1.0, @0.7, @0.9, @0.7, @0.8, @0.7]; scale.keytimes = @[@0.13, @0.26, @0.39, @0.52, @0.65, @0.8]; scale.repeatcount = 1; scale.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctionlinear]; [view.layer addanimation:scale forkey:@"scaleanimation"]; }
finally want maintain button in shrunk state after touch ended.
1. should seek permanently alter layers scale? touchesbegan? touchesended? 2. how should that? (see "<=== correct?" line)
i wouldn't utilize of code have written.
it looks you're trying "bounce" scale of button looks user has affected physically.
to can utilize modern block based animation , new (to ios7) version uses spring damping create animation curve.
this give effect of bouncing (but need numbers right).
[uiview animatewithduration:0.8 delay:0.0 usingspringwithdamping:0.0 // mess around initialspringvelocity:0.0 // , options:0 animations:^{ view.transform = cgaffinetransformmakescale(0.7, 0.7); } completion:^(bool finished){ // if want reset button here }];
you can read more function here...
apple docs uiview.
my blog function , parameters mean.
ios iphone core-animation cakeyframeanimation
No comments:
Post a Comment