Explanation of Animatekeyframeswithduration method in UIView of iOS7
In IOS7, a method was added to UIView to use keyframe animations directly without the help of Coreanimation, which is animatekeyframeswithduration
The following is the use of source code:
////VIEWCONTROLLER.M////Created by youxianming on 14/11/26.//Copyright (c) 2014 youxianming. All rights reserved.//#import "ViewController.h"@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; [Self runanimatekeyframes];}- (void) Runanimatekeyframes {/** * relativeduration when the animation starts * Relativestarttime The duration of the animation*/[UIView animatekeyframeswithduration:6. F Delay:0.0Options:uiviewkeyframeanimationoptioncalculationmodelinear Animations:^{[UIView addkeyframewithrelativestarttime:0.0 //the time starting at the beginning of the 6 second (the animation starts in the No. 0 second)Relativeduration:1/3.0 //duration of animation relative to 6 seconds (animation lasts 2 seconds)animations:^{Self.view.backgroundColor=[Uicolor Redcolor]; }]; [UIView addkeyframewithrelativestarttime:1/3.0 //the time starting at the beginning of the 6 second (the animation starts in the 2nd second)Relativeduration:1/3.0 //duration of animation relative to 6 seconds (animation lasts 2 seconds)animations:^{Self.view.backgroundColor=[Uicolor Yellowcolor]; }]; [UIView addkeyframewithrelativestarttime:2/3.0 //the time starting at the beginning of the 6 second (the animation starts in the 4th second)Relativeduration:1/3.0 //duration of animation relative to 6 seconds (animation lasts 2 seconds)animations:^{Self.view.backgroundColor=[Uicolor Greencolor]; }]; } Completion:^(BOOL finished) {[Self runanimatekeyframes]; }];}@end
Details of the place:
Explanation of Animatekeyframeswithduration method in UIView of iOS7