IOS-simple animation

Source: Internet
Author: User
ArticleDirectory
    • Move left and right
    • Rotate
    • Zoom

Http://disanji.net/2010/12/18/ios-realize-animation-effect/

By Fgamers Posted on December 18, 2010 89 reading comments (0)

The simplest animation effect in IOS is that there are no key frames, such as moving left and right, beating up and down, rotating, and scaling. The key frame should be a little more complex, and the path should be set.

IOS can achieve the preceding simple animation effect without the help of heavy libraries such as OpenGL 2D. It is very easy to write.

Move left and right

Moving up or down is similar.

 

CodeAs follows:

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
-   (  Void  ) Loadview {      [  [ Uiapplication sharedapplication ] Setstatusbarhidden :  Yes Withanimation : Uistatusbaranimationslide ] ; Uiimage * Image =  [ Uiimage imagenamed :  @  "1.jpg"  ] ; Cgcolorspaceref colorspace = Cgcolorspacecreatedevicergb (  ) ; Cgcontextref Context = Cgbitmapcontextcreate (  Null , 768 , 1024 , 8 , 4   *   768 , Colorspace, kcgimagealphapremultipliedfirst ) ; Cgrect rect = Cgrectmake (  0 , 0 , 768 , 1024  ) ; Cgcolorref fillcolor =   [  [ Uicolor whitecolor ] Cgcolor ] ; Cgcontextsetfillcolor ( Context, cgcolorgetcomponents ( Fillcolor )  ) ; Cgcontextmovetopoint ( Context, 160.0f, 2300000f ) ; Cgcontextaddlinetopoint ( Context, 6000000f, 2300000f ) ; Cgcontextaddlinetopoint ( Context, 6000000f, 1000000f ) ; Cgcontextaddlinetopoint ( Context, 370.0f, 50366f ) ; Cgcontextaddlinetopoint ( Context, 2000000f, 1000000f ) ; Cgcontextclosepath ( Context ) ; Cgcontextclip ( Context ) ; Cgcontextdrawimage ( Context, rect, image. cgimage ) ; Cgimageref imagemasked = Cgbitmapcontextcreateimage ( Context ) ; Cgcontextrelease ( Context ) ; Uiimage * Newimage =   [ Uiimage imagewithcgimage : Imagemasked ] ; Cgimagerelease ( Imagemasked ) ; Uiimageview * Backview =  [  [ Uiimageview alloc ] Initwithframe :  [  [ Uiscreen mainscreen ] Applicationframe ]  ] ; Self. View =  [  [ Uiview alloc ] Initwithframe :  [  [ Uiscreen mainscreen ] Applicationframe ]  ] ; [ Self. View addsubview : Backview ] ; Backview. Image = Newimage; backview. Alpha =  0.3 ; Cabasicanimation * Theanimation1; // Define the animation  // Swing left and right Theanimation1 =  [ Cabasicanimation animationwithkeypath :  @  "Transform. Translation. X"  ] ; Theanimation1.fromvalue =  [  Nsnumber Numberwithfloat : 0  ] ; Theanimation1.tovalue =  [  Nsnumber Numberwithfloat :-  100  ] ; Theanimation1.duration =  5.5 ; // Animation duration Theanimation1.repeatcount =  6 ; // Number of animation repetitions Theanimation1.autoreverses =  Yes ; // Automatic repetition?  [ Backview. layer addanimation : Theanimation1 forkey :  @ "Animatelayer"  ] ; [ Newimage release ] ; [ Image release ] ; } 
Rotate

The effect is similar to the following:

 

Here, the figure is rotated by PI (180 °. You only need to replace part of the animation code:

12
Theanimation1=[Cabasicanimation animationwithkeypath:@"Transform"]; Theanimation1.tovalue= [ NsvalueValuewithcatransform3d:Catransform3dmakerotation(3.1415,0,0,1.0) ];
Zoom

Scaling is similar to this:

 

The code can be replaced:

12
Theanimation1=[Cabasicanimation animationwithkeypath:@"Transform. Scale"]; Theanimation1.tovalue= [NsnumberNumberwithdouble:1.5];

Link: http://marshal.easymorse.com/archives/3727

Reprint EDIT: fgamers reprint address: http://disanji.net/2010/12/18/ios-realize-animation-effect/
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.