ios - Point to Point Animation -
http://postimg.org/image/8bwxdp4bj/7124c28f/ want make animation shown in above image .i using code .they became move infinity , view not appear because involved in loop. newer in ios . please help.what stuck.any appreciated.
for (i=0; i<3; i++) { if (i==0) { first.backgroundcolor=[uicolor blackcolor]; second.backgroundcolor=[uicolor yellowcolor]; third.backgroundcolor=[uicolor yellowcolor]; button.backgroundcolor=[uicolor yellowcolor]; i=1; } if (i==1) { first.backgroundcolor=[uicolor yellowcolor]; second.backgroundcolor=[uicolor blackcolor]; third.backgroundcolor=[uicolor yellowcolor]; button.backgroundcolor=[uicolor yellowcolor]; i=2; } if (i==2) { first.backgroundcolor=[uicolor yellowcolor]; second.backgroundcolor=[uicolor yellowcolor]; third.backgroundcolor=[uicolor blackcolor]; button.backgroundcolor=[uicolor yellowcolor]; i=3; } if (i==3) { first.backgroundcolor=[uicolor yellowcolor]; second.backgroundcolor=[uicolor yellowcolor]; third.backgroundcolor=[uicolor yellowcolor]; button.backgroundcolor=[uicolor blackcolor]; i=0; } }
firstly make global variable keeps track of button's background changed , array stores buttons.
@interface classname() { int index = 0; nsarray *buttons; }
now in initialization method, this
[first setbackgroundcolor:[uicolor yellowcolor]]; [second setbackgroundcolor:[uicolor yellowcolor]]; [third setbackgroundcolor:[uicolor yellowcolor]]; [button setbackgroundcolor:[uicolor yellowcolor]]; buttons = @[first, second, third, button]; [self performselector:@selector(changecolor) withobject:nil afterdelay:1.0f];
now in changecolor
method, this
- (void)changecolor { uibutton *btn = [buttons objectatindex:index]; [btn setbackgroundcolor:[uicolor blackcolor]]; uibutton *prevbtn = [buttons objectatindex:((index - 1) + 4) % 4]; [prevbtn setbackgroundcolor:[uicolor yellowcolor]]; index = ++ index % 4; [self performselector:@selector(changecolor) withobject:nil afterdelay:1.0f]; }
Comments
Post a Comment