The following is the source code:
// // ViewController.m // // Created by YouXianMing on 14/11/26. // Copyright (c) 2014年 YouXianMing. All rights reserved. // #import "ViewController.h" @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self runAnimateKeyframes]; } - (void)runAnimateKeyframes { /** * when the relativeDuration animation starts * relativeStartTime the duration of the animation */ [UIView animateKeyframesWithDuration:6.f delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{ [UIView addKeyframeWithRelativeStartTime:0.0 // Time relative to the start of 6 seconds (start animation at 0 seconds) relativeDuration:1/3.0 // Relative to the duration of the 6 second animation (the animation lasts 2 seconds) animations:^{ self.view.backgroundColor = [UIColor redColor]; }]; [UIView addKeyframeWithRelativeStartTime:1/3.0 // Time relative to the start of 6 seconds (the animation starts at the 2nd second) relativeDuration:1/3.0 // Relative to the duration of the 6 second animation (the animation lasts 2 seconds) animations:^{ self.view.backgroundColor = [UIColor yellowColor]; }]; [UIView addKeyframeWithRelativeStartTime:2/3.0 // Time relative to the start of 6 seconds (the animation starts at the 4th second) relativeDuration:1/3.0 // Relative to the duration of the 6 second animation (the animation lasts 2 seconds) animations:^{ self.view.backgroundColor = [UIColor greenColor]; }]; } completion:^(BOOL finished) { [self runAnimateKeyframes]; }]; } @end
Details: