iOS development - Core Animation (core animation)

Core Animation for iOS development

Introduction to Core Animation

  • Core Animation acts directly on CALayer, not UIVIew;
  • Core Animation, Chinese translation for core animation, it is a set of very powerful animation processing API, use it to make very dazzling animation effects, and often get twice the result with half the effort. That said, very powerful functionality can be achieved with a small amount of code.
  • Core Animation is cross-platform and can be used in both Mac and iOS.
  • Core Animation animations are background operations, so they do not block the main thread. (Do not block the main thread, that is, Apple actively releases the block object for us after executing the animation block, which can also be understood as performing operations while executing the animation).

How to use Core Animation

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

Use of CAAnimation ( 核心)

  • CAAnimation class inheritance structure diagram
    CAAnimation class inheritance structure diagram
  • CAAnimation is the parent class of all animation classes, but it cannot be used directly, and its subclasses should be used. ( 注意)
  • Common properties of CAAnimation
duration:动画的持续时间
repeatCount:动画的重复次数
timingFunction:控制动画运行的节奏
  • Animation subclasses that can be used by CAAnimation
CABasicAnimation
CAKeyframeAnimation
CATransition
CAAnimationGroup

CAMediaTiming is an animation protocol (protocol

Use of CAPropertyAnimation

  • CAPropertyAnimation is a subclass of CAAnimation, but it cannot be used directly. To create animation objects, you should use its two subclasses:
  • CABasicAnimation和CAKeyframeAnimation
它有个NSString类型的keyPath属性,你可以指定CALayer的某个属性名为keyPath,并且对CALayer的这个属性的值进行修改,达到相应的动画效果。比如,指定@"position"为keyPath,就会修改CALayer的position属性的值,以达到平移的动画效果

Supplementary Instructions

  • The parent class of all animation objects is responsible for controlling the duration and speed of animation. It is an abstract class and cannot be used directly. Its specific subclasses should be used.

CAMediaTiming animation protocol (protocol) attribute analysis

duration:动画的持续时间
repeatCount:动画的重复次数
repeatDuration:动画的重复时间
removedOnCompletion:默认为YES,代表动画执行完毕后就从图层上移除,图形会恢复到动画执行前的状态。如果想让图层保持显示动画执行后的状态,那就设置为NO,不过还要设置fillMode为kCAFillModeForwards
fillMode:决定当前对象在非active时间段的行为。比如动画开始之前,动画结束之后
beginTime:可以用来设置动画延迟执行时间,若想延迟2s,就设置为CACurrentMediaTime()+2,CACurrentMediaTime()为图层的当前时间
timingFunction:速度控制函数,控制动画运行的节奏
delegate:动画代理

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325423638&siteId=291194637