ios - Coordinating two UIView animations on UIButton down/up -
i'm trying build animation around uibutton. uibutton has uiimageview contains image i'd shrink when uibutton held downwards , when uibutton allow go, i'd play separate animation bounce.
the issue i'm experiencing right 2nd part of animation doesn't seem play if press downwards , quickly. if press , hold (wait first animation finish), allow go, seems work fine.
here's relevant code:
-(void)presseddown { [uiview animatewithduration:0.2 delay:0 options:uiviewanimationoptioncurveeaseout animations:^{ self.heartpart.layer.transform = catransform3dmakescale(0.8, 0.8, 1); } completion:nil]; } -(void)pressedup { [uiview animatewithduration:0.8 delay:0.0 usingspringwithdamping:20 initialspringvelocity:200 options:uiviewanimationoptionbeginfromcurrentstate animations:^{ self.heartpart.layer.transform = catransform3didentity; } completion:nil]; }]; }
in viewdidload
add together following:
[self.heartbutton addtarget:self action:@selector(pressedup) forcontrolevents:uicontroleventtouchupinside]; [self.heartbutton addtarget:self action:@selector(presseddown) forcontrolevents:uicontroleventtouchdown];
any thought how can 2 animations sequence , not interrupt each other on quick press?
here's potential plan of action. maintain 2 global variables, bool buttonpressed
, nsdate *buttonpressdate
. when button pressed, should set buttonpressed
true , set buttonpressdate
current date. in touch method, set buttonpressed
false , check whether time interval between buttonpressdate
, current date greater duration of animation. if is, run touch animation; if not, return. in completion block of touch downwards method, check if button still pressed. if is, nothing; if it's not pressed anymore, run touch animation.
the effect you'll using approach should following: if tap button quickly, run total 0.2-second shrink animation , run enlarge animation in sequence.
now, if don't want touch downwards animation run in case of quick touch, should delay first animation , check if button still pressed when start it. if quick touch, run modified animation covered both touch downwards , touch phases.
ios objective-c animation uibutton
No comments:
Post a Comment