我打算做一个在背景中不断变化颜色的应用程序。在我的想法中,应该有一个 UIView 动画在另一个应该一遍又一遍地重复自己之后。这是我的尝试
self.view.backgroundColor = [UIColor whiteColor];
[UIView animateWithDuration:4 delay:0 options: UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAutoreverse animations:^{
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.view.backgroundColor = [UIColor yellowColor];
NSLog(@"1");
} completion:^(BOOL finished){
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.view.backgroundColor = [UIColor greenColor];
NSLog(@"2");
} completion:^(BOOL finished){
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.view.backgroundColor = [UIColor redColor];
NSLog(@"3");
} completion:^(BOOL finished){
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.view.backgroundColor = [UIColor purpleColor];
NSLog(@"4");
} completion:NULL];
}];
}];
}];
} completion:NULL];
然而,这不仅看起来很乱,而且不会重复。有什么建议吗?