ios - Objective-C completion block for animation within for loop (pause loop processing) -


i have method fade in, fade out button label (shown below):

    -(void)fade:(nsstring *)text  {       nslog(@"starting fade in symbol %@",text);      [self.symbolbutton setalpha:0.0f];      [self.symbolbutton settitle:text forstate:uicontrolstatenormal];      [uiview animatewithduration:2 animations:^{          [self.symbolbutton setalpha:1.0f];       } completion:^(bool finished) {       nslog(@"starting fade out symbol %@",text);     [uiview animatewithduration:2 animations:^{     [self.symbolbutton setalpha:0.0f];     } completion:nil];     }];  } 

this works intended. however, rather single string, want cycle through contents of array (eg. fade-in "a", fade-out "a", fade-in "b", fade-out "b".....).

in above code, completion block waits fade-in finish before starting fade-out (good). however, if try , process array using loop (modify method accept array , nest actions in loop iterates array), loop cycles rather waiting first character complete.

is there way use completion block in second animation action pause processing of loop - or going in wrong way?

you may try this. didn't test idea should work

nsarray<uibutton*>* arrbuttons; nsstring* text;  (int = 0 ; < arrbuttons.count; i++) {     uibutton* b = arrbuttons[i];     b.alpha = 0.0f;     [b settitle:text forstate:uicontrolstatenormal];      [uiview animatekeyframeswithduration:2 delay:4*i options:0 animations:^{          b.alpha = 1.0f;      } completion:^(bool finished) {          nslog(@"starting fade out symbol %@",text);          [uiview animatewithduration:2 animations:^{             b.alpha = 0.0f;         } completion:nil];      }];  } 

Comments