ios - How to animate an object multiple times with delay in swift 3? -
i want animate multiple buttons multiple times in succession when button required animate twice or more, code doesn't work @ all.
//function animates button func buttonanimationchain(buttoncolor:uibutton, idelaytime: int){ uiview.animate(withduration: 0.5, delay: double(idelaytime), options: [], animations: { buttoncolor.alpha = 0.0; }, completion: {finished in buttoncolor.alpha = 1.0; }) } //function displays sequence func showsequence(igeneratedarraysequence: [int]){ var idelaytime:int = 0; _ in 1 ... igeneratedarraysequence.count{ if(igeneratedarraysequence[idelaytime] == 1){ buttonanimationchain(buttoncolor: buttonblue, idelaytime: idelaytime); } if(igeneratedarraysequence[idelaytime] == 2){ buttonanimationchain(buttoncolor: buttonyellow, idelaytime: idelaytime); } if (igeneratedarraysequence[idelaytime] == 3){ buttonanimationchain(buttoncolor: buttonpurple, idelaytime: idelaytime); } if(igeneratedarraysequence[idelaytime] == 4){ buttonanimationchain(buttoncolor: buttongreen, idelaytime: idelaytime); }//end of if statement idelaytime += 1; }//end of loop }//end of function
when generated array has numbers not repeated, animation works once button needs animated twice, nothing shows up. think happens because button stays in inactive state while function turns active , can't think of solution fix this. i've tried using sleep() function generates wonky results.
the problem calling animations 1 after another, without waiting first end , uiview animations asynchronous.
maybe should use recursive function, call first button, , when ends call again second button , on.
Comments
Post a Comment