objective c - How to return BOOL from animateWithDuration? -
i try create method , return bool type animatewithduration. object seems not detected on completion block. can explain me, why can happen?
+ (bool)showanimationfirstcontent:(uiview *)view { bool status = no; cgrect show = [swfirstcontent rectfirstcontentshow]; [uiview animatewithduration:duration delay:delay options:uiviewanimationoptionbeginfromcurrentstate animations:^{ view.frame = show; } completion:^( bool finished ) { status = yes; }]; return status; }
thanks advance.
you setting status value inside block executed asynchronously. meaning, return statement not guaranteed executed after block executed. know when animation finished need declare method in different way.
+ (void)showanimationfirstcontent:(uiview *)view completion:(void (^)(void))callbackblock{ cgrect show = [swfirstcontent rectfirstcontentshow]; [uiview animatewithduration:duration delay:delay options:uiviewanimationoptionbeginfromcurrentstate animations:^{ view.frame = show; } completion:^( bool finished ) { callbackblock(); }]; }
and can call method this:
[myclass showanimationfirstcontent:aview completion:^{ //this block executed when animation finished [self dowhateveryouwant]; }];
you may want read bit more how block works.
hope helps.
Comments
Post a Comment