First of all, I am new to this Xcode/Objective-C thing, so go easy on me! :) I made a test app that, by pressing some buttons, the background changes. I have a red, blue, green, white, black and revive button.
I made the app change the color of the backgrnd by pressing all the color buttons. However, I want to make the app cycle through the colors, say 100 times very fast when pressing the Revive button. For some reason, it doesnt work.
The following is the code that isn't working:
Using the code below, only changes to the last color.
- (IBAction)Revive:(id)sender {
for (int y=0; y < 100; y++) {
view1.backgroundColor = [UIColor redColor];
view1.backgroundColor = [UIColor greenColor];
view1.backgroundColor = [UIColor blueColor];
view1.backgroundColor = [UIColor whiteColor];
view1.backgroundColor = [UIColor blackColor];
}
}
Using the code below, whitout the loop, the app fades from white to black
- (IBAction)Revive:(id)sender {
[UIView animateWithDuration:0.2 animations:^{
view1.backgroundColor = [UIColor redColor];
view1.backgroundColor = [UIColor greenColor];
view1.backgroundColor = [UIColor blueColor];
view1.backgroundColor = [UIColor whiteColor];
view1.backgroundColor = [UIColor blackColor];
}];
[UIView commitAnimations];
}
Anyone knows why this is happening and a solution to my problem?