iOS Animation learning Note one

Source: Internet
Author: User

iOS complex animations are all combined with Bezier curves. Therefore, to learn iOS animation, you must first understand the Bezier curve. There are many tutorials on the Bezier line, and there is not much to be explained here. The main thing is to talk about animation.

One, draw a simple curve

Let's first prepare a wavy Bezier curve:

cgpoint startPoint =cgpointmake(a);

cgpoint endPoint =cgpointmake(+);

cgpoint onePoint =cgpointmake(,);

cgpoint twopoint =cgpointmake(a);

uibezierpath *path = [uibezierpathbezierpath];

Path. linewidth =10.0f;

path. Linecapstyle =Kcglinecapround;

[Path movetopoint: StartPoint];

[path addcurvetopoint: EndPointcontrolPoint1: OnePoint controlPoint2: twopoint];

But the Bezier curve is an abstract object. Its display is to be based on the Calayer. The subclass Cashapelayer of Calayer is a layer class dedicated to displaying a curve.

Cashapelayer *layer = [cashapelayerlayer];

Layer. path = [path cgpath];

Layer. Strokecolor = [[uicolorredcolor] cgcolor];

Layer. FillColor = [[uicolorclearcolor] cgcolor];

[Self. View. Layer addsublayer: layer];


Second, add animations to layer layers

this time has actually drawn a curve. But it is static, and to animate it must be used in conjunction with Caanimation. Caanimation is an abstract animation class. Here I take a picture of the Apple document to show the hierarchical relationship of core animation, which is a package for OpenGL and core Grapgics.




To add a gradual animation to this curve, use cabasicanimation. Where Cabasicanimation is inherited from the Capropertyanimation,

Capropertyanimation is inherited from the caanimation. Cabasicanimation has only three properties, namely (ID) Fromvalue, (ID) tovalue, (ID) byvalue.

Take a look at the code first:

Cabasicanimation *anim = [cabasicanimationanimation];

Anim.keypath = @ "Strokeend";

Anim.fromvalue = @ (0);

Anim.tovalue = @ (1);

Anim.Duration = 2;

Anim. Removedoncompletion =NO;

Anim. Fillmode =kcafillmodeforwards;


[Layer addanimation: Animforkey:@ "Basicanim"];

At this point, we can already draw a curve on the fly.

So, what is the function of the two attributes Fromvalue and Tovalue respectively?

First, we notice that the three attributes are of type ID, which can be followed by any form of value.

For example, zoom animation:

scaleanimation.fromvalue = [Nsvalue valuewithcatransform3d:catransform3didentity];

Scaleanimation.tovalue = [Nsvalue valuewithcatransform3d:catransform3dmakescale (0.1,0.1, 1.0 )];


Transparency changes:

Opacityanimation.fromvalue = [NSNumber numberwithfloat:1.0];

Opacityanimation.tovalue = [NSNumber numberwithfloat:0.1];


Rotate Animation:

Tranformanimation.fromvalue = [NSNumber numberwithfloat:0.f];

Tranformanimation.tovalue = [NSNumber numberwithfloat:m_pi];


From the above we can know that Fromvalue represents the initial state of an animation, Tovalue represents the end state of an animation.





iOS Animation learning Note one

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.