Home >Web Front-end >HTML Tutorial >Core Animation1-Introduction_html/css_WEB-ITnose

Core Animation1-Introduction_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:41:15948browse

1. Introduction to Core Animation

* Core Animation, translated into Chinese as Core Animation, is a set of very powerful animation processing APIs. It can be used to create very dazzling animation effects, and Often you get twice the result with half the effort. In other words, very powerful functions can be achieved with a small amount of code.

* Core Animation can be used on Mac OS X and iOS platforms.

* Boss Qiao personally demonstrated the power of Core Animation to you at the 2007 WWDC conference: click to view the video

* The animation execution process of Core Animation is operated in the background and will not Block the main thread.

* It should be noted that Core Animation acts directly on CALayer, not UIView.

Back to top

2. Steps to use Core Animation

1. To use it, you need to first add the QuartzCore.framework framework and introduce the main header file 0015dadec5922034a4069860b696bbb8

2. Initialize a CAAnimation object and set some animation-related properties

3. Add the CAAnimation object to CALayer by calling CALayer's addAnimation:forKey: method , so that the animation can be started

4. The animation in CALayer can be stopped by calling CALayer's removeAnimationForKey: method

Back to top

3. CAAnimation

* As can be seen from the previous description, if you want to execute animation, you must initialize a CAAnimation object.

* In fact, under normal circumstances, we use more subclasses of CAAnimation, so let’s take a rough look at the inheritance structure of CAAnimation:

Black line Represents inheritance, black text represents the class name, and white text represents attributes. Among them, CAMediaTiming is a protocol.

1. Common attributes of CAAnimation

* CAAnimation is the parent class of all animation classes, but it cannot be used directly, its subclasses should be used

* Common attributes are :

1> duration: duration of animation

2> repeatCount: number of repetitions of animation

3> timingFunction: control the rhythm of animation running

Optional values ​​for timingFunction are:

  • kCAMediaTimingFunctionLinear (Linear): Uniform speed, giving you a relatively static feeling
  • kCAMediaTimingFunctionEaseIn (Progressive): The animation enters slowly and then accelerates away
  • kCAMediaTimingFunctionEaseOut (gradually fade out): The animation enters at full speed, and then slows down to reach the destination
  • kCAMediaTimingFunctionEaseInEaseOut (gradually fades out): The animation enters slowly, accelerates in the middle, and then slows down to reach the destination. This is the default animation behavior.
  • 4> delegate: animation proxy, used to monitor the execution process of animation

    The methods that the proxy object needs to implement are: (these methods are defined in a certain category)

    1 @interface NSObject (CAAnimationDelegate)2 // 动画开始执行的时候触发这个方法3 - (void)animationDidStart:(CAAnimation *)anim;4 5 // 动画执行完毕的时候触发这个方法6 - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;7 @end

    * All properties introduced above belong to CAAnimation, therefore, all subclasses of CAAnimation can use them.

    2. Others

    * CAPropertyAnimation cannot be used directly, and its subclasses must be used

    * Therefore, animation classes that can be used There are only 4 left: CABasicAnimation, CAKeyframeAnimation, CATransition, CAAnimationGroup

    Back to top

    4. CAPropertyAnimation

    * CAPropertyAnimation is a subclass of CAAnimation , but it cannot be used directly. To create animation objects, you should use its two subclasses: CABasicAnimation and CAKeyframeAnimation

    * It has a keyPath attribute of NSString type. You can specify a property of CALayer named keyPath. , and modify the value of this property of CALayer to achieve the corresponding animation effect. For example, specifying @"position" as keyPath will modify the value of CALayer's position attribute to achieve the translation animation effect

    * Therefore, after initializing the subclass object of CAPropertyAnimation, you must first set the keyPath. Be clear about which property of CALayer you want to modify and what kind of animation is being executed

    Copyright statement: This article is an original article by the blogger http://www.zuiniusn.com and may not be used without the permission of the blogger Reprint.

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn