On UIView animation programming art

Source: Internet
Author: User

One, size animation (change frame)

-(void== CGRectMake (self.anview.frame.origin.x-), self.anview.frame.origin.y-); [UIView animatewithduration: 1 animations:^= rect;} completion:^(BOOL finished) {[UIView animatewithduration:  1 animations:^= originalrect;}];}];}

Second, stretch animation (change bounds)

-(void= self.anView.bounds; // Although this rect's X, Y is different from the original, the animation only changes the width and height CGRect rect = CGRectMake (00); [ UIView animatewithduration:1 animations:^= rect;} completion:^(BOOL Finished) {[UIView animatewithduration:1 animations:^= originalbounds;}];}];}

Third, transfer animation (change center)

-(void== Cgpointmake (self.anview.center.x, self.anview.center.y-); [ UIView animatewithduration:0.3 animations:^= point ;} completion:^(BOOL finished {[UIView animatewithduration:1 animations:^= originalpoint;}];}];}

Iv. Rotate Animation (change transform)

-(void) Transform{cgaffinetransform Originaltransform=Self.anView.transform; [UIView animatewithduration:2animations:^{//self.anView.transform = Cgaffinetransformmakescale (0.6, 0.6);//Zoom//self.anView.transform = cgaffinetransformmaketranslation ( -60);Self.anView.transform = Cgaffinetransformmakerotation (4.0f);} Completion:^(BOOL finished) {[UIView animatewithduration:2animations:^{self.anView.transform=Originaltransform;}];}];}

V. Transparency Animation (change alpha)

-(void) alpha{[uiview animatewithduration:2 animations:^0.3;} Completion:^(BOOL finished) {[UIView animatewithduration:2 animations:^1 ;}];}];}

VI. Background color keyframes animation (change background)

-(void) Changebackground{[uiview animatekeyframeswithduration:9.0Delay0. F Options:uiviewkeyframeanimationoptioncalculationmodelinear animations:^{[UIView addkeyframewithrelativestarttime:0. F Relativeduration:1.0/4animations:^{Self.anView.backgroundColor= [Uicolor colorwithred:0.9475Green0.1921Blue0.1746Alpha1.0];}]; [UIView addkeyframewithrelativestarttime:1.0/4Relativeduration:1.0/4animations:^{Self.anView.backgroundColor= [Uicolor colorwithred:0.1064Green0.6052Blue0.0334Alpha1.0];}]; [UIView addkeyframewithrelativestarttime:2.0/4Relativeduration:1.0/4animations:^{Self.anView.backgroundColor= [Uicolor colorwithred:0.1366Green0.3017Blue0.8411Alpha1.0];}]; [UIView addkeyframewithrelativestarttime:3.0/4Relativeduration:1.0/4animations:^{Self.anView.backgroundColor= [Uicolor colorwithred:0.619Green0.037Blue0.6719Alpha1.0];}]; [UIView addkeyframewithrelativestarttime:3.0/4Relativeduration:1.0/4animations:^{Self.anView.backgroundColor=[Uicolor Whitecolor];}];} Completion:^(BOOL finished) {NSLog (@"End of animation");}];}

Vii. Spring Animation (from iOS7.0)

-(void) Springanimation{cgrect Originalrect=Self.anView.frame; CGRect rect= CGRectMake (self.anview.frame.origin.x- the, SELF.ANVIEW.FRAME.ORIGIN.Y, -, -); [UIView animatewithduration:0.4Delay0Usingspringwithdamping:0.5Initialspringvelocity:4Options:uiviewanimationoptioncurvelinear animations:^{self.anView.frame=rect;} Completion:^(BOOL finished) {[UIView animatewithduration:1Delay1Usingspringwithdamping:0.5Initialspringvelocity:4Options:uiviewanimationoptioncurvelinear animations:^{self.anView.frame=Originalrect;} Completion:^(BOOL finished) {}];}];}

Eight, transition animation

-(void) transitionanimation{[uiview transitionWithView:self.anView Duration:2.0 Options : Uiviewanimationoptiontransitionflipfromleft animations:^{//self.anView.backgroundColor = [ Uicolor Bluecolor];} completion:^(BOOL finished) {[UIView transitionWithView:self.anView Duration:2.0 options: Uiviewanimationoptiontransitionflipfromright animations:^{//Self.anView.backgroundColor = [Uicolor Greencolor];} completion:^(BOOL finished) {}];}];}

Ix. about parameter Option selection description

1.UIViewAnimationOptions

Uiviewanimationoptionlayoutsubviews//Animate when layout child controls

Uiviewanimationoptionallowuserinteraction//Allow user interaction when animating

Uiviewanimationoptionbeginfromcurrentstate//Start animation from current state

Uiviewanimationoptionrepeat//Infinite repeat animations

Uiviewanimationoptionautoreverse//Perform animation loop

Uiviewanimationoptionoverrideinheritedduration//Ignore execution time settings for nested animations

Uiviewanimationoptionoverrideinheritedcurve//Ignore curve settings for nested animations

Uiviewanimationoptionallowanimatedcontent//Transitions: Redraw a view when animating

Uiviewanimationoptionshowhidetransitionviews//Transitions: removing (adding and removing layers) animation effects

Uiviewanimationoptionoverrideinheritedoptions//Do not inherit parent animation settings

Uiviewanimationoptioncurveeaseinout//Time curve, slow-forward slow-out (default value)

Uiviewanimationoptioncurveeasein//Time curve, slow forward

Uiviewanimationoptioncurveeaseout//Time curve, slow out

Uiviewanimationoptioncurvelinear//Time curve, constant speed

Uiviewanimationoptiontransitionnone//Transitions, do not use animations

Uiviewanimationoptiontransitionflipfromleft//transitions, turning pages from left to right

Uiviewanimationoptiontransitionflipfromright//transitions, turning from right to left

Uiviewanimationoptiontransitioncurlup//transitions, bottom to top Curl page

Uiviewanimationoptiontransitioncurldown//transitions, from top to bottom curl up and down page

Uiviewanimationoptiontransitioncrossdissolve//transitions, cross disappearing and appearing

Uiviewanimationoptiontransitionflipfromtop//transitions, turning pages from top to bottom

Uiviewanimationoptiontransitionflipfrombottom//transitions, rotating from bottom to page

2.UIViewKeyframeAnimationOptions

Uiviewanimationoptionlayoutsubviews//Animate when layout child controls

Uiviewanimationoptionallowuserinteraction//Allow user interaction when animating

Uiviewanimationoptionbeginfromcurrentstate//Start animation from current state

Uiviewanimationoptionrepeat//Infinite repeat animations

Uiviewanimationoptionautoreverse//Perform animation loop

Uiviewanimationoptionoverrideinheritedduration//Ignore execution time settings for nested animations

Uiviewanimationoptionoverrideinheritedoptions//Do not inherit parent animation settings

Uiviewkeyframeanimationoptioncalculationmodelinear//operation mode: Continuous

Uiviewkeyframeanimationoptioncalculationmodediscrete//operation mode: Discrete

uiviewkeyframeanimationoptioncalculationmodepaced//operation mode: Uniform execution

Uiviewkeyframeanimationoptioncalculationmodecubic//operation mode: Smooth

uiviewkeyframeanimationoptioncalculationmodecubicpaced//Operation mode: smooth and uniform

As far as UIView's animation is concerned, Uiviewkeyframeanimationoptions is tight in keyframes and the rest is uiviewanimationoptions.

X. Summary and expansion

1.UIView animation is mainly about changing the uiview of the self-brought property

2.UIView animations can achieve the same effect in many ways

3.Spring Animation iOS7.0 above only

4.UIViewKeyframeAnimationOptions uses the KeyFrames animation, the rest is enumerated with uiviewanimationoptions

Xi. Source Address

Https://github.com/minggo620/iOSViewAnimation

On UIView animation programming art

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.