iOS animation development One of the use of--uiviewanimation animationsFirst, Introduction
the success of an app, in addition to the perfect function, the user experience also occupies a great proportion, the rational use of animation, can be very good to enhance the user experience. In iOS development, the commonly used animation processing has the UIView animation programming and the core animation programming, in which the UIView animation use is simple, the development application is very extensive. This blog, mainly discusses the use of UIView animation.
Ii. Several methods of UIView animation
+ (void) Animatewithduration: (nstimeinterval) Duration animations: (void (^) (void )) animations;
This is the least parameter method, we can set a time and block blocks to complete the animation, the Time parameter is the duration of the animation execution, block block in order to perform the animation action, specifically can perform those actions, we will say later. For example, the view gradient is transparent within 1S:
[UIView animatewithduration:1 animations:^{_myview.alpha=0; }];
+ (void ) Animatewithduration: (nstimeinterval ) Duration animations: (void (^) (void ) Animations Completion: (void (^) (bool finished)) completion;
This function will take two block blocks, the usage is similar to the first function, set an execution time and an execution action, a second block block can add an animation after the end of the action, as a supplement, such as the effect of the following code, in the 1S view gradient to transparent, after the end of the animation, View changes back to opaque in an instant:
[UIView animatewithduration:1 animations:^{_myview.alpha=0; } completion:^ (BOOL finished) {if (finished) {_myview.alpha=1; } }];
+ (void ) Animatewithduration: (nstimeinterval ) Duration delay: (nstimeinterval " delay options: (uiviewanimationoptions ) Options animations: (void (^) (void ) Animations Completion: (void (^) (bool finished)) completion;
This function in addition to the above properties, you can set the delay execution, and can set an animation effect parameters, this parameter is an enumeration, it can affect the performance of the animation, will be summarized later.
+ (void) Animatewithduration: (Nstimeinterval) Duration delay: (Nstimeinterval) Delay usingspringwithdamping: (CGFloat) Dampingratio initialspringvelocity: (CGFloat) Velocity Options: (uiviewanimationoptions) Options Animations: (void(^) (void)) Animations Completion: (void(^) (BOOLfinished)) completion;
This function is a new function after iOS7, through this function, we can easily produce the effect of cool animation, the core of this function is two damping parameters, the parameter dampingratio can be understood as the strength of the spring effect, set 1 does not rebound effect, set 0 will be a sharp damping rebound. The velocity parameter is used to set the initial speed of the spring.
Third, UIView animation can manipulate the view properties
With The introduction above, we've learned several functions that use animations, so what are those properties that can animate?
The official documentation tells us that these properties can be animated by the above methods:
iv. Animation execution option settings
< Span style= "FONT-SIZE:16PX;" > in the relevant function of UIView execution animation, there are
enum { //This section is the setting of the underlying properties UIViewAnimationOptionLayoutSubviews = 1 << 0,// Set child view to show animation with parent view uiviewanimationoptionallowuserinteraction = 1 << 1,//allows the user to interact with the animation as it executes uiviewanimationoptionbeginfromcurrentstate = 1 << 2,// Allows new animations to be performed when the animation is performed UIViewAnimationOptionRepeat = 1 << 3,// Set Animation loop Execution UIViewAnimationOptionAutoreverse = 1 << 4,//setting animation reverse execution, must be used together with repeat execution uiviewanimationoptionoverrideinheritedduration = 1 << 5,//force animation to use the initial time value UIViewAnimationOptionOverrideInheritedCurve = 1 << 6,//force animation to use the initial curve value uiviewanimationoptionallowanimatedcontent = 1 << 7,//Animate view real-time refresh uiviewanimationoptionshowhidetransitionviews = 1 << 8,//set the view to be hidden when switching, rather than removing uiviewanimationoptionoverrideinheritedoptions = 1 << 9,// //This section property sets the linear effect of animation playback uiviewanimationoptioncurveeaseinout = 0 << 16,//fade First end deceleration UIViewAnimationOptionCurveEaseIn = 1 << 16,/ /fade in initial deceleration uiviewanimationoptioncurveeaseout = 2 << 16,//fade End deceleration UIViewAnimationOptionCurveLinear = 3 << 16,//linear Uniform execution //This section to set UIView toggle effect UIViewAnimationOptionTransitionNone = 0 << 20, uiviewanimationoptiontransitionflipfromleft = 1 << 20,// Cut from the left UIViewAnimationOptionTransitionFlipFromRight = 2 << 20,//cut from the right UIViewAnimationOptionTransitionCurlUp = 3 << 20,//from the top stereoscopic into Uiviewanimationoptiontransitioncurldown = 4 << 20,//from the following stereoscopic entry uiviewanimationoptiontransitioncrossdissolve = 5 << 20,//Dissolution effect UIViewAnimationOptionTransitionFlipFromTop = 6 << 20,//cut from top UIViewAnimationOptionTransitionFlipFromBottom = 7 < < 20,//from below};
Tip: Properties can use | To make multiple merges.
iOS animation development One of the use of--uiviewanimation animations