Transferred from: http://blog.csdn.net/totogo2010/article/details/8501812
Animation effects provide a smooth user experience for State or page transitions, and in iOS we don't need to write our own animation code, and Core animation provides a rich API to achieve the animation you need.
Uikit only use UIView to show animations, animations support UIView These property changes below:
- Frame
- Bounds
- Center
- Transform
- Alpha
- BackgroundColor
- Contentstretch
1. commitanimations mode using UIView animation
[CPP]View PlainCopy
- -(void) Viewdidload
- {
- [Super Viewdidload];
- UIButton *button = [UIButton buttonwithtype:uibuttontyperoundedrect];
- [Button settitle:@"Change" forstate:uicontrolstatenormal];
- Button.frame = CGRectMake (10, 10, 60, 40);
- [Button addtarget:self action: @selector (Changeuiview) forcontrolevents:uicontroleventtouchupinside];
- [Self.view Addsubview:button];
- }
- -(void) changeuiview{
- [UIView beginanimations:@"animation" context:nil];
- [UIView setanimationduration:1.0f];
- [UIView Setanimationcurve:uiviewanimationcurveeaseinout];
- [UIView setanimationtransition:uiviewanimationtransitionflipfromright ForView:self.view Cache:yes];
- [UIView commitanimations];
- }
Here are the effects of the click Change (two kinds): There are four types of animation constants
[CPP]View PlainCopy
- Uiviewanimationtransitionnone,
- Uiviewanimationtransitionflipfromleft,
- Uiviewanimationtransitionflipfromright,
- Uiviewanimationtransitioncurlup,
- Uiviewanimationtransitioncurldown,
1.2 Swapping 2 view positions in the View controller
[self. View exchangesubviewatindex:1 withsubviewatindex:0];
Add two view first, one redview and one Yellowview
[CPP]View PlainCopy
- -(void) Viewdidload
- {
- [Super Viewdidload];
- UIView *redview = [[UIView alloc] initwithframe:[[uiscreen mainscreen] bounds]];
- Redview.backgroundcolor = [Uicolor Redcolor];
- [Self.view Addsubview:redview];
- UIView *yellowview = [[UIView alloc] initwithframe:[[uiscreen mainscreen] bounds]];
- Yellowview.backgroundcolor = [Uicolor Yellowcolor];
- [Self.view Addsubview:yellowview];
- UIButton *button = [UIButton buttonwithtype:uibuttontyperoundedrect];
- [Button settitle:@"Change" forstate:uicontrolstatenormal];
- Button.frame = CGRectMake (10, 10, 300, 40);
- [Button addtarget:self action: @selector (Changeuiview) forcontrolevents:uicontroleventtouchupinside];
- [Self.view Addsubview:button];
- UIButton *button1 = [UIButton buttonwithtype:uibuttontyperoundedrect];
- [Button1 settitle:@"Change 1" forstate:uicontrolstatenormal];
- Button1.frame = CGRectMake (10, 60, 300, 40);
- [Button1 addtarget:self Action: @selector (ChangeUIView1) forcontrolevents:uicontroleventtouchupinside];
- [Self.view Addsubview:button1];
- }
[CPP]View PlainCopy
- - (void) changeuiview1{
- [uiview beginanimations:@
- [uiview setanimationduration : 1.0f];
- [uiview setanimationcurve: uiviewanimationcurveeaseinout];
- [uiview setanimationtransition:uiviewanimationtransitioncurldown forview:self.view cache:yes];
- // swap 2 view positions in the View controller
- [self.view exchangesubviewatindex:1 withsubviewatindex:0];
- [uiview commitanimations];
- }
This looks like two pages.1.3, [UIView setanimationdidstopselector:@selector(animationfinish:)];
Before commitanimations the message, you can set the callback after the animation is complete, by:
[UIView setanimationdidstopselector:@selector(animationfinish:)];
2. Use: Catransition
[CPP]View PlainCopy
- -(void) changeuiview2{
- Catransition *transition = [catransition animation];
- Transition.duration = 2.0f;
- Transition.type = Kcatransitionpush;
- Transition.subtype = Kcatransitionfromtop;
- [Self.view exchangesubviewatindex:1 withsubviewatindex:0];
- [Self.view.layer addanimation:transition forkey:@"animation"];
- }
The type of transition.type can have
Fade, push, uncover, cover
NSString * Const Kcatransitionfade;
NSString * Const Kcatransitionmovein;
NSString * Const Kcatransitionpush;
NSString * Const kcatransitionreveal;
These four species, Transition.subtype also have four kinds of
NSString * Const Kcatransitionfromright;
NSString * Const Kcatransitionfromleft;
NSString * Const Kcatransitionfromtop;
NSString * Const Kcatransitionfrombottom;
2.2 Types of animations of the private type:
Cube, absorb, flip, ripple, page turn, reverse flip, lens on, lens off
[CPP]View PlainCopy
- animation.type = @
- animation.type = @ "Suckeffect";
- animation.type = @
- Animation.type = @ "Rippleeffect";
- "Pagecurl";
- Animation.type = @ "Pageuncurl"   
- animation.type = @ "camerairishollowopen ";
- animation.type = @ "camerairishollowclose ";
Is the effect of the first cube cube: The Startprogress endprogress property of the 2.3 catransition property is of type float.
You can control the process of animation, which lets the animation rest on an animation point, with a value between 0.0 and 1.0. Endprogress is greater than or equal to startprogress. For example, the top of the cube to go, you can set endprogress= 0.5, so that the animation stays in the rotation of the general position. The above private animation effect, in the actual application to be cautious to use. Because these animations may be rejected by the App Store when it is reviewed. 3, UIView + (void) Animatewithduration: (nstimeinterval) duration animations: (void (^) (void)) Animations completion: ( void (^) (BOOL finished)) Completion method. This method is only supported after the iOS4.0. The UIView method is simpler and easier to use than 1 miles. Add Moveview in Didview.
[CPP]View PlainCopy
- Moveview = [[UIView alloc] Initwithframe:cgrectmake (10, 180, 200, 40)];
- Moveview.backgroundcolor = [Uicolor blackcolor];
- [Self.view Addsubview:moveview];
[CPP]View PlainCopy
- -(void) changeuiview3{
- [UIView animatewithduration:3 animations:^ (void) {
- Moveview.frame = CGRectMake (10, 270, 200, 40);
- }completion:^ (BOOL finished) {
- UILabel *label = [[UILabel alloc] Initwithframe:cgrectmake (20, 20, 40, 40)];
- Label.backgroundcolor = [Uicolor blackcolor];
- [Self.view Addsubview:label];
- }];
- }
Then move the animation with UIView Animatewithduration and add a label after the animation is finished.
3.2, animatewithduration of the use of nesting
[CPP]View PlainCopy
- -(void) changeuiview3{
- [UIView Animatewithduration:2
- delay:0
- Options:uiviewanimationoptioncurveeaseout animations:^ (void) {
- Moveview.alpha = 0.0;
- }completion:^ (BOOL finished) {
- [UIView Animatewithduration:1
- delay:1.0
- Options:uiviewanimationoptionautoreverse | Uiviewanimationoptionrepeat
- animations:^ (void) {
- [UIView setanimationrepeatcount:2.5];
- Moveview.alpha = 1.0;
- }completion:^ (BOOL finished) {
- }];
- }];
- }
The effect of this nesting is to first turn the view into transparent, from transparent to opaque, repeat 2.5 times transparent to opaque effect. The code for the example in this article: Animatedemo
Jongfangzhi (http://blog.csdn.net/totogo2010)
This article follows "Attribution-non-commercial use-consistent" authoring public agreement
iOS animation effects and implementations