I mostly show the proportions of the change animations, but that doesn't mean you can't animate the layer's more properties! Here is an example of using jnwspringanimation to rotate a layer using a spring action.
Jnwspringanimation *scale = [Jnwspringanimation animationwithkeypath:@"Transform.rotation"];Scale. Damping=Ten;Scale. Stiffness= -;Scale. Mass=3;Scale. Fromvalue= @(0);Scale. Tovalue= @ (m_pi_2);[RedBall. LayerAddanimation:scale Forkey:scale. KeyPath];RedBall. Transform= Cgaffinetransformmakerotation (m_pi_2);
Since this is a rotational animation, the start and end values are defined by the radian angle. We use a convenient function CGAffineTransformMakeRotation() to set the final value of the model layer to 2 π.
Next we're going to set the damping and stiffness of the springs as shown in the previous 3 layers example will typically result in a similar value for the exponential decay type action. We animate its position, not the scale of the layer.
Jnwspringanimation *scale = [Jnwspringanimation animationwithkeypath:@"Transform.translation.x"];Scale. Damping=7;Scale. Stiffness=7;Scale. Mass=1;Scale. Fromvalue= @(0);Scale. Tovalue= @( -);[RedBall. LayerAddanimation:scale Forkey:scale. KeyPath];RedBall. Transform= Cgaffinetransformmaketranslation ( -,0);
We want to animate the location of the critical path to "transform.translation.x", which is the--x coordinate from left to right. We'll move it 400 pixels to the right, so Tovalue is 400, to set the final value and keep the ball where we're animating, we need to set the ball's transform to CGAffineTransformMakeTranslation(400, 0) . This function is a simple way to change the translation component of the view's change matrix, which receives two parameters, X and y changes.
Of course, we can animate many properties at once. Here is a code that animates both proportions and rotations. See if you can find the difference between animations with individual properties.
Jnwspringanimation *scale = [Jnwspringanimation animationwithkeypath:@"Transform.scale"];Scale. Damping=9;Scale. Stiffness=9;Scale. Mass=1;Scale. Fromvalue= @(1);Scale. Tovalue= @(4.0);[RedBall. LayerAddanimation:scale Forkey:scale. KeyPath];RedBall. Transform= Cgaffinetransformscale (RedBall. Transform,4.0,4.0);Jnwspringanimation *rotate = [Jnwspringanimation animationwithkeypath:@"Transform.rotation"];Rotate. Damping=9;Rotate. Stiffness=9;Rotate. Mass=1;Rotate. Fromvalue= @(0);Rotate. Tovalue= @ (M_PI);[RedBall. LayerAddanimation:rotate forkey:rotate. KeyPath];RedBall. Transform= Cgaffinetransformrotate (RedBall. Transform, M_PI);
The first animation is a scale change from 1.0 to 4.0 to four times times the size. The first difference from the code in the previous example is when we set the actual change value of the model layer after adding the animation (so it can maintain the final value.) Instead of using a CGAffineTransformMakeScale() function to enter a new scale, it uses a function with a similarly confusing name CGAffineTransformScale() and receives three parameters. CGAffineTransformMakeScale()(include make in it) it is assumed that the change matrix you want to change is a regular, default, non-touching, identity transformation matrix that has just created the view at this point.
On the other hand, the first parameter that receives three parameters CGAffineTransformScale() is the matrix of changes you want to change from the beginning. This can be an identity change or a variant that already has some operations, such as being rotated, scaled, panned, and so on. The reason we use this function and the current transformation of the view as the first parameter is that we are adding two animations to it and they all manipulate the morph matrix of the layer. If we use CGAffineTransformMakeScale() it, it will affect the deformation adjustment of all the second animations, using the start identity transform instead of the layer morph of the second animation setting that was recently updated. By introducing the current morph value, we can ensure that the most recent value is used for our operation, and this will contain the final value of the second animation.
The second animation rotates the angle of our object π. Let's see what the animations that contain proportions and rotational deformations look like.
It's cool, right? We don't need to set the same time curve for each animation, because this is two separate animated objects, and we can individually control the properties of each spring. Here is an example of a scale and rotation animation whose proportional spring uses an exponential decay type of spring action (no elasticity), and the rotation animation is very elastic.
Here is another example of adding two animations at the same time. This time it combines a position (PAN) animation and a proportional warp.
I don't know about you, but I'm a little bored with just animating these color blocks. I think it's time to get into some real-world, real app examples that use jnwspringanimation to animate spring action.
Finished viewing the integration set: Https://github.com/Cloudox/Motion-Design-for-iOS
All rights reserved: Http://blog.csdn.net/cloudox_
Motion Design for IOS (24)