Core Animation Cabasicanimation

Source: Internet
Author: User
Tags repetition

Core animation is a very powerful set of animation processing APIs that can be used to make very flashy animations, often with less effort!

1. Development steps:

Initializes an animated object (caanimation) and sets some animation-related properties

Add an animated object to the layer (Calayer) to start the animation

The animation execution of Core animation is performed in the background and does not block the main thread

Main classes of 2.Core animation

The layer class that provides the display content: Calayer and its subclasses

Animation and Timing classes: Caanimation and its subclasses, camediatiming

Layout and Constraint classes: Caconstraint, Caconstraintlayoutmanager

Transaction classes, combining layer classes when atomic updates: Catransaction, caactiontransition

3.CABasicAnimation Basic animation, a subclass of Capropertyanimation

Property Description:

Fromvalue:keypath the initial value of the corresponding property

Tovalue:keypath the end value of the corresponding property

3.1 Animation Process Description:

As the animation progresses, the value of the keypath corresponding property is gradually changed from Fromvalue to Tovalue during the duration of the duration length.

KeyPath content is an animated animatable property of Calayer

If Fillmode=kcafillmodeforwards is removedoncomletion=no at the same time, after the animation finishes, the layer remains displayed after the animation is executed. But in essence, the property value of the layer is still the initial value before the animation is executed, and it is not really changed.

On the code:

1 caanimation

Bounds transform

KeyPath: Specifies a property value for the layer that is animated by modifying the property value

Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@ "Transform.scale"];

2 Setting properties

1> The starting value of the animation

Animation.fromvalue = @0.5;

2> the end value of the animation

Animation.tovalue = @3;


3> duration of animation

Animation.duration = 3;

4> Auto Replay (takes more than one time)

animation.autoreverses = YES;

5> the animation after the animation finishes (if you do not remove the animation, it needs to be used with the Fill method)

Animation.removedoncompletion = NO; (the default is YES)

6> Fill Mode

Animation.fillmode = Kcafillmodeforwards;

Animation.fillmode = Kcafillmodebackwards;


Kcafillmodeforwards: Preserves the effect after the animation ends

Kcafillmodebackwards: Before the animation starts, it will advance to the beginning of the animation effect (open delay can be seen)

All kcafillmodeboth:2 have

None of them kcafillmoderemoved:2.


7>begintime: Start time (animation is performed after one second delay)

Animation.begintime = Cacurrentmediatime () +1;

8>timeoffset Time offset (starts the animation of the 2nd second and executes until the specified duration)

Animation.timeoffset = 2;

9>repeatcount: Number of repetitions

Animation.repeatcount = 2;

10>repeatduration: Total time to repeat (if there is a conflict with repetition, follow the repetition time)

Animation.repeatduration = 4;

11>speed: Animation speed (and duration conflict)

Animation.speed =.3;

3 Adding an animated object to a layer

Key: Mark

Animation object in this copy; So the attribute is written before adding

[Self.myImageView.layer addanimation:animation forkey:@ "animation"];

Core Animation Cabasicanimation

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: 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.