[IOS Diary] Cabasicanimation KeyPath Encyclopedia and Use cases

Source: Internet
Author: User
Tags set time

Reprinted from Http://www.cnblogs.com/bucengyongyou/archive/2012/12/20/2826590.html Mark

Cabasicanimation own only three property Fromvalue Tovalue Byvalue

When you create a cabasicanimation, you need to specify a start and end value through-setfromvalue and-settovalue. When you add the underlying animation to the layer, it starts to run. When an animation completes with a property, such as animating with the position attribute, the layer immediately returns to its initial position

Remember that when you animate, you use at least 2 objects. These objects are the layers themselves, a layer or layer of inherited objects, and in the previous example you assign to the layer of the Cabasicanimation object. Because you set the final value (destination) for the animated object, it does not mean that when the animation is finished, the properties of the layer change to the final value. When the animation is complete, you must display the settings layer properties, so that after the animation, your layer can really go to the value of the property you set.

You can simply stop the animation at the end of your point, but it is only a visual effect. The actual value of the layer is still the same. To really change the intrinsic value, as you have just said, you have to show the setting of that attribute. For example, to display the settings of the attribute, you need to call the-setposition method in the layer. However, this can cause a little problem.

If you display the value of a layer attribute by-set This method, the default animation will be performed instead of the animation you set previously. The way you set up the location is shown in table 3-9. Notice that we've created the underlying animation using position, but the-setposition method we've shown on the layer overrides the animation we set, and the underlying animation we set up is completely useless. If you use this code, you will see that although our layer ended up in the right place, it used the default 0.25 seconds instead of the 5 seconds we displayed in the animation.

1 2 3 4 Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@ "position"]; [Animation Setfromvalue:[nsvalue Valuewithpoint:startpoint]]; [Animation Settovalue:[nsvalue Valuewithpoint:endpoint]]; [Animation setduration:5.0]; [Layer Setposition:endpoint]; [Layer addanimation:animation Forkey:nil];

So now the question is, how can you use the animation we set up? Look at the last line in table 3-9 and note that Forkey: This parameter is set to nil. This is why the animation cannot override the default animation. If you change the last act [layer addanimation:animation forkey:@ "position"], the animation will work according to the time we set. This tells the layer to use the new animation we specified for the critical path when it was necessary to animate.

Here are some of the inherited swimming properties

Autoreverses

When you set this property to YES, after it arrives at the destination, the animation returns to the starting value, instead of the direct jump to the start value.

Duration
Duration This parameter you are quite familiar with. It sets the time it takes to start the value to the end value. The duration is affected by the properties of the speed. Removedoncompletion
This property defaults to YES, which means that the animation is automatically removed from the layer after the specified time period has been completed. This is generally not necessary.

If you want to use this animation again, you need to set this property to NO. In this case, the next time you set the animation properties by using the-set method, it will use your animation again, not the default animation.

Speed

The default value is 1.0. This means that the animation plays at the default speed. If you change the value to 2.0, the animation will play at twice times the speed. The effect is to halve the duration. If you specify a duration of 6 seconds and a speed of 2.0, the animation will play for 3 seconds---Half of the duration.

BeginTime

This property is useful in group animations. It specifies when the animation starts to play, depending on the duration of the parent animation group. The default is 0.0. Group Animation discusses "Animation Grouping" in the next paragraph.

Timeoffset

If a time offset is set, the animation is not really visible until the time elapsed according to the execution time in the parent animation group.

RepeatCount

The default is 0, which means that the animation will only play once. If you specify an infinitely large number of repetitions, use 1e100f. This should not be used with the Repeatdration property.

RepeatDuration

This property specifies how long the animation should be repeated. The animation repeats until the set time elapses. It should not be used in conjunction with RepeatCount.

The following English excerpt from Apple's official document, will be Fromvalue tovalue byvalue how to use

The interpolation values are used as follows:

Both Fromvalue and Tovalue are non-nil. Interpolates between Fromvalue and Tovalue.

Fromvalue and Byvalue are non-nil. Interpolates between Fromvalue and (Fromvalue + byvalue).

Byvalue and Tovalue are non-nil. Interpolates between (Tovalue-byvalue) and Tovalue.

Fromvalue is Non-nil. Interpolates between Fromvalue and the current presentation value.

Tovalue is Non-nil. Interpolates between the current value of keypath in the target layer ' s presentation layer.

Byvalue is Non-nil. Interpolates between the current value of keypath in the target layer ' s presentation layer and that value plus byvalue.

All properties are nil. Interpolates between the previous value of KeyPath in the target layer ' s presentation layer and the current value of Keypa Th in the target layer ' s presentation layer.

Other methods or attributes are

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.