IOS animation Summary

Source: Internet
Author: User

I. Basic Method: Use the uiviewanimation extension of the uiview class
Function Description

+ ( Void ) Beginanimations :( nsstring *) animationid context :( Void *) Context; //  Start preparing the animation  
+ ( Void ) Commitanimations; // Run the animation

// There is no get method, and the following set does not work in the quick outer call
+ ( Void ) Setanimationdelegate :( ID ) Delegate ; // Delegate default = Nil
+ (Void ) Setanimationwillstartselector :( SEL) selector; // Default = NULL.-animationwillstart :( nsstring *) animationid context :( void *) Context
+ ( Void ) Setanimationdidstopselector :( SEL) selector; // Default = NULL.-animationdidstop :( nsstring *) animationid finished :( nsnumber *) finished context :( void *) Context
+ ( Void ) Setanimationduration :( nstimeinterval) duration; // Default = 0.2 animation time
+ ( Void ) Setanimationdelay :( nstimeinterval) delay; // Default = 0.0 how long will the animation be delayed?
+ ( Void ) Setanimationstartdate :( nsdate *) startdate; // Default = now ([nsdate date]) animation start date? I don't know what to use .--
+ ( Void ) Setanimationcurve :( uiviewanimationcurve) curve; // Default = uiviewanimationcurveeaseinout Animation Mode
+ ( Void ) Setanimationrepeatcount :( Float ) Repeatcount; // Default = 0.0. May be fractional repeated times
+ ( Void ) Setanimationrepeatautoreverses :( bool) repeatautoreverses; // If default = No. Yes, the animation (not the last time) is dynamically restored to the initial state after the animation ends.
+ ( Void ) Setanimationbeginsfromcurrentstate :( bool) fromcurrentstate; // Default = No. yes. Stop the previous animation. From now on, the current view position is always used for new animations -- allowing animations to "pile up" on each other. otherwise, the last end state is used for the animation (the default ).

+ ( Void ) Setanimationtransition :( uiviewanimationtransition) transition forview :( uiview *) View cache :( bool) cache; // When an animation is added to a view, the cache is efficient when yes, but the content on the interface cannot be updated during the animation process. If no, each frame is re-painted and can be updated in real time.
+ ( Void ) Setanimationsenabled: (bool) enabled; // Ignore animation settings?
+ (Bool) areanimationsenabled;

An animatedCode

 
[Uiview beginanimations: Nil context: Nil];
[Uiview setanimationcurve: uiviewanimationcurvelinear];
[Uiview setanimationduration:2.7];
[Uiview setanimationtransition: Transition forview: Self. View cache: Yes];
//Operation >>>
[Self. View exchangesubviewatindex:0Withsubviewatindex:1];
//End <
[Uiview commitanimations];

Transition value range

TypedefEnum{
Uiviewanimationtransitionnone,
Uiviewanimationtransitionflipfromleft,
Uiviewanimationtransitionflipfromright,
Uiviewanimationtransitioncurlup,
Uiviewanimationtransitioncurldown,
} Uiviewanimationtransition;

Features: basic, easy to use, but limited effect

Ii. Block Mode: Use the uiviewanimationwithblocks extension of the uiview class

Function Description

+ ( Void ) Animatewithduration :( nstimeinterval) duration delay :( nstimeinterval) delay options :( uiviewanimationoptions) Options animations :( Void (^ )( Void ) Animations completion :( Void (^) (Bool finished) completion _ osx_available_starting (_ mac_na ,__ iphone_4_0 );//  Interval, latency, and Animation Parameters (seems useless ?), Change the block on the page and end the block.  

+ ( Void ) Animatewithduration :( nstimeinterval) Duration animations :( Void (^ )( Void ) Animations completion :( Void (^) (Bool finished) completion _ osx_available_starting (_ mac_na ,__ iphone_4_0 ); // Delay= 0.0, Options = 0

+ ( Void ) Animatewithduration :( nstimeinterval) Duration animations :( Void (^ )( Void ) Animations _ osx_available_starting (_ mac_na ,__ iphone_4_0 ); // Delay= 0.0, Options = 0, completion = NULL

+ ( Void ) Transitionwithview :( uiview *) view duration :( nstimeinterval) Duration options :( uiviewanimationoptions) Options animations :( Void (^ )( Void ) Animations completion :( Void (^) (Bool finished) completion _ osx_available_starting (_ mac_na ,__ iphone_4_0 );

+ ( Void ) Transitionfromview :( uiview *) fromview toview :( uiview *) toview duration :( nstimeinterval) Duration options :( uiviewanimationoptions) Options completion :( Void (^) (Bool finished) completion _ osx_available_starting (_ mac_na ,__ iphone_4_0 ); // Toview added to fromview. superview, fromview removed from its superview interface replacement, the options parameter here is valid

Example:

 
[Uiview animatewithduration:0.7Delay:0Options:0Animations: ^ (){
Self. View. Alpha =0.2;
[Self. View exchangesubviewatindex:1Withsubviewatindex:0];
Self. View. Alpha =1;
} Completion: ^ (bool finished)
{

}];

When areanimationsenabled is no, it cannot be animated.

[Uiview transitionfromview: limage toview: mimage duration:0.7Options: Options completion: ^ (bool finished)
{
If(Finished ){
[Self. View addsubview: limage];
[Self. View sendsubviewtoback: limage];
[Self. View sendsubviewtoback: mimage];
}
}];

Options Value Range

 Enum {
Uiviewanimationoptionlayoutsubviews = 1 < 0 ,
Uiviewanimationoptionallowuserinteraction = 1 < 1 , // Turn on user interaction while animating
Uiviewanimationoptionbeginfromcurrentstate = 1 < 2 , // Start all views from current value, not Initial Value
Uiviewanimationoptionrepeat = 1 < 3 , // Repeat animation indefinitely
Uiviewanimationoptionautoreverse = 1 < 4 , // If repeat, run animation back and forth
Uiviewanimationoptionoverrideinheritedduration = 1 < 5 ,// Ignore nested duration
Uiviewanimationoptionoverrideinheritedcurve = 1 < 6 , // Ignore nested Curve
Uiviewanimationoptionallowanimatedcontent = 1 < 7 , // Animate contents (applies to transitions only)
Uiviewanimationoptionshowhidetransitionviews = 1 < 8 , // Flip to/from hidden state instead of adding/removing

Uiviewanimationoptioncurveeaseinout = 0 < 16 , // Default
Uiviewanimationoptioncurveeasein = 1 < 16 ,
Uiviewanimationoptioncurveeaseout = 2 < 16 ,
Uiviewanimationoptioncurvelinear = 3 < 16 ,

Uiviewanimationoptiontransitionnone = 0 < 20 , // Default
Uiviewanimationoptiontransitionflipfromleft = 1 < 20 ,
Uiviewanimationoptiontransitionflipfromright = 2 < 20 ,
Uiviewanimationoptiontransitioncurlup = 3 < 20 ,
Uiviewanimationoptiontransitioncurldown = 4 < 20 ,
Uiviewanimationoptiontransitioncrossdissolve = 5 < 20 , // Ios5
Uiviewanimationoptiontransitionflipfromtop = 6 < 20 , // Ios5
Uiviewanimationoptiontransitionflipfrombottom = 7 < 20 , // Ios5
};
Typedef nsuinteger uiviewanimationoptions;

Features: quick and convenient, with more results. You can dynamically display the progressive changes of each element attribute on the interface as in Example 1 above.

Iii. Core Method: Use catransition class
Use the quartzcore. Framework
There is an official example:Viewtransitions
Basically

 catransition * transition = [catransition animation]; 
transition. duration = 0.7 ;
transition. timingfunction = [camediatimingfunction functionwithname: kcamediatimingfunctioneaseineaseout];
transition. type = kcatransitionmovein; // {kcatransitionmovein, kcatransitionpush, kcatransitionreveal, kcatransitionfade };
// more private {@ "cube", @ "suckeffect ", @ "oglflip", @ "rippleeffect", @ "pagecurl", @ "pageuncurl", @ "camerairishollowopen", @ "camerairishollowclose "};
transition. subtype = kcatransitionfromleft; // {kcatransitionfromleft, kcatransitionfromright, kcatransitionfromtop, kcatransitionfrombottom };
transition. DeleGate = self;
[self. view. layer addanimation: Transition forkey: Nil];
// what to do
[self. view exchangesubviewatindex: 1 withsubviewatindex: 0 ];

Note that the interface adjustment (the two interfaces displayed before and after the animation) must be completed within the animation time. Otherwise, there will be no effect and it will also affect the next time. What I tested is not too complete, you can write the example mselector: withobject: afterdelay by yourself.

Features: the animation effect is relatively large (but private), and the animation between uiviewcontroller can be realized.

Demo: animations.zip

 

From: http://www.cnblogs.com/v2m_/archive/2011/10/28/2227979.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.