Навин дал хороший первый старт, но вы можете показать немного больше уроков, анимируя изменение цвета.
- (void)viewDidLoad {
[super viewDidLoad];
// Set up the initial background colour
self.view.backgroundColor = [UIColor redColor];
// Set up a repeating timer.
// This is a property,
self.changeBgColourTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeColour) userInfo:nil repeats:YES];
}
- (void) changeColour {
// Don't just change the colour - give it a little animation.
[UIView animateWithDuration:0.25 animations:^{
// No need to set a flag, just test the current colour.
if ([self.view.backgroundColor isEqual:[UIColor redColor]]) {
self.view.backgroundColor = [UIColor greenColor];
} else {
self.view.backgroundColor = [UIColor redColor];
}
}];
// Now we're done with the timer.
[self.changeBgColourTimer invalidate];
self.changeBgColourTimer = nil;
}