IOS Animation-CABasicAnimation and CAKeyFrameAnimation

Source: Internet
Author: User

IOS Animation-CABasicAnimation and CAKeyFrameAnimation details & Differences & contacts, and cabasicanimation details

1. First, let's take a look at their inheritance diagram circulating on the Internet:

From the above we can see that both CABasicAnimation and CAKeyframeAnimation inherit from CAPropertyAnimation. CAPropertyAnimation provides basic animation attribute settings such as keyPath, additive, and cumulative.

 

2. Detailed explanation

1) CABasicAnimation

CABasicAnimation provides the most basic animation attribute settings and is a simple keyframe animation performance. CABasicAnimation can be viewed as a simple animation of CAKeyframeAnimation, because it only has the key frame (keyframe) at the beginning and end ).

We can create a CABasicAnimaiton object using the keyPath method. CABasicAnimation provides fromValue, toValue, and byValue settings (interpolation ). The three attributes define the trajectory of an animation, and the minimum two values cannot be blank.

After the start and end values of CABasicAnimation are set, the intermediate values are calculated by interpolation. The interpolation calculation is specified by timingFunction, and timingFunction is empty by default, use liner (Uniform Motion ). For example, if we set an animation of position and set the start value PointA and end value PointB, their motion first calculates the intermediate motion value PointCenter between PointA and PointB, pointCenter uses the timingFunction to specify the value, and the animation defaults to linear motion at a constant speed.

 

2) CAKeyFrameAnimation

CAKeyframeAnimation provides the attributes of the general keyframe animation function layer for us to use. It allows us to set a specific array, which is the animation value during motion. That is to say, CAKeyframeAnimation supports multiple animation value settings.

CAKeyFrameAnimation can be defined in two ways: CGPath and array values.

CGPath only applies to the anchorPoint or position attribute of layer. Values is flexible. KeyTimes is an optional parameter that defines each part of a keyframe. Its value ranges from 0.0 to 1.0. Each time value in the keyTimes array corresponds to each frame in values. When keyTimes is not set, the time of each keyframe is equally divided. Each element in the keyTimes array defines the duration value of the corresponding keyframe as a small part of the total animation duration. The value of each element must be greater than or equal to the previous value.

 

3. Different from the contact

1) CABasicAnimation can be viewed as a CAKeyframeAnimation with a maximum of two key frames.

 

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.