iOS Animation summary

Source: Internet
Author: User

iOS Animation summary I. Basic mode: Using the uiviewanimation extension of the UIView class
+ (void) Beginanimations: (NSString *) Animationid context: (void *) context; Start preparing animations
+ (void) commitanimations;//Run animation

//There is no get method, the following set is invalid in fast-out
+ (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 Delay How long it takes to start an animation
+ (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 is fractional repeat number of times
+ (void) setanimationrepeatautoreverses: (BOOL) repeatautoreverses; Default = NO. Yes, the animation (not the last time) after the end of the dynamic recovery to the beginning of the state
+ (void) Setanimationbeginsfromcurrentstate: (BOOL) fromcurrentstate; Default = NO. YES, stop the previous animation and start the new animation from now on. The current view position are always used for new animations--allowing animations to ' pile up ' on E Ach other. Otherwise, the last end of the state was used for the animation (the default).

+ (void) Setanimationtransition: (uiviewanimationtransition) Transition Forview: (UIView *) View cache: (BOOL) cache; Add animation to the view, the cache is yes when the time is more efficient, but the animation process can not update the content on the interface, no when every frame is redrawn, can be updated in real time
+ (void) setanimationsenabled: (BOOL) enabled; Do you want to ignore some animation settings
+ (BOOL) areanimationsenabled;


A code for an animation

[UIView Beginanimations:nil Context:nil];
[UIView Setanimationcurve:uiviewanimationcurvelinear];
[UIView setanimationduration:2.7];
[UIView setanimationtransition:transition ForView:self.view Cache:yes];
Operation>>>
[Self.view exchangesubviewatindex:0 withsubviewatindex:1];
end<<<<<<
[UIView commitanimations];

Where transition value range

typedef enum {
Uiviewanimationtransitionnone,
Uiviewanimationtransitionflipfromleft,
Uiviewanimationtransitionflipfromright,
Uiviewanimationtransitioncurlup,
Uiviewanimationtransitioncurldown,
} uiviewanimationtransition;

Features: Basic, easy to use, but with limited effect

Two. 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, delay, animation parameters (like useless?), interface change block, end block

+ (void) Animatewithduration: (nstimeinterval) duration animations: (void (^) (void)) animations completion: (void (^) (BOOL finished)) Completion

+ (void) Animatewithduration: (nstimeinterval) duration animations: (void (^) (void)) animations

+ (void) Transitionwithview: (UIView *) View Duration: (nstimeinterval) Duration options: (uiviewanimationoptions) Options animations: (void (^) (void)) animations completion: (void (^) (BOOL finished))

+ (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 is replaced by its Superview interface, where the options parameters are valid

Example:

[UIView animatewithduration:0.7 delay:0 options:0 animations:^ () {
Self.view.alpha = 0.2;
[Self.view exchangesubviewatindex:1 withsubviewatindex:0];
Self.view.alpha = 1;
} completion:^ (BOOL finished)
{

}];

When Areanimationsenabled is no, it cannot be animated

[UIView transitionfromview:limage toview:mimage duration:0.7 options: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 <<,//default
Uiviewanimationoptioncurveeasein = 1 <<,
uiviewanimationoptioncurveeaseout = 2 <<,
uiviewanimationoptioncurvelinear = 3 <<,

uiviewanimationoptiontransitionnone = 0 <<,//default
uiviewanimationoptiontransitionflipfromleft = 1 <<,
uiviewanimationoptiontransitionflipfromright = 2 <<,
Uiviewanimationoptiontransitioncurlup = 3 <<,
Uiviewanimationoptiontransitioncurldown = 4 <<,
uiviewanimationoptiontransitioncrossdissolve = 5 << 20,//ios5
uiviewanimationoptiontransitionflipfromtop = 6 << 20,//ios5
Uiviewanimationoptiontransitionflipfrombottom = 7 << 20,//ios5
};
typedef nsuinteger Uiviewanimationoptions;

Features: Fast and convenient, more effective. The dynamic display of the gradual change of the element properties of the interface can be realized as above example 1

for less complex animations, the above is very concise, because there is only one statement, if the animation is too complex, write in such a statement will appear lengthy, for code debugging is not so convenient.
Three: Core animation
Core animation is a combination of a set of graphics rendering, projection, and animation libraries in the OBJC language, making the user interface very easy to create, using the following methods:
1: High-performance synthesis with a simple programming approach
2: Use layer objects to create complex user interfaces.
3: Lightweight data structure, capable of animating hundreds of layers at the same time.
4: Not dependent on the main thread of the application, animations run in separate threads
5: Improved application performance. The application only needs to redraw its changing portions (local refresh).
6: Flexible layout Management Method
2. Related classes
With core animation, developers do not need to use the underlying API or OpenGL to create beautiful animated interfaces.
The core animation class is divided into the following:
1: Provide a layer for displaying content
2: Animations and Time classes
3: Layout and Constraint classes
4: The execution class that divides multiple layers into several atomic updates
2.1 Layers (layer)
A layer is the foundation of the core animation, an instance of the view, a Calayer instance as the parent layer (Superlayer), and all the child layers added on this layer, the layer structure created
2.2 Animations and Time classes
Implicit animations
The changes to many visual properties of a layer can produce an implicit animation effect, because these properties are associated by default with an animation. By simply setting a visual property value, the layer will animate the gradient from the current value to the value being set. For example, setting a layer's hidden property to True will trigger a faded animation effect.

An explicit animation
Explicit animations do not alter the properties of a layer by creating an animated class and specifying the desired animation effect.
All of the core animation classes are inherited by the abstract class caanimation. The caanimation uses the Camediatiming protocol. camediatiming specifies the duration, speed, and number of repetitions of the animation. Caanimation also uses the Caaction protocol, which specifies the standard way to start an animation when responding to actions triggered by a layer.

The core animation also provides other animation classes
Catransition,
Catransition provides a conversion effect that affects the entire layer, during which it causes the layer to produce gradients (fade), push-pull (push), and reveal (reveal) animation effects. These common conversion effects can be extended through the core drawing filters.

Caanimation,
Caanimation allows a large number of animated objects to be divided into groups and can be run concurrently.
Capropertyanimation, which is a subclass of caanimation, supports layers to specify a critical path for the layer during animation.
Cabasicanimation. This class provides a simple interpolation for the properties of a layer.
Cakeyframeanimation,
Cakeyframeanimation provides support for key-frame animations. You can specify a critical path for the properties of a layer
2.3 Layout Management Class
The Cakeyframeanimation class is used to manage the layout of all child layers, and each instance encapsulated by the Caconstraint class describes the geometric position relationship between each sub-layer.
2.4 Executive Management Classes
The properties of the animation layer can be set to be modified as part of the execution, and Catransaction is responsible for displaying many animations into several batches of atomic type updates.

 

iOS Animation summary

Related Article

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.