IOS----Core Animation介绍5

来源:互联网 发布:数据库脱机 编辑:程序博客网 时间:2024/06/07 02:24
原文地址:http://superman474.blog.163.com/blog/static/120661462011857731100/
layer actions的触发一般发生在:layer从layer-tree上插入或者删除,layer属性值被改变,或者应用程序显式的请求。通常的anction被触发导致动画显示。
     
1.action对象的作用
  action对象通过CAAction协议去响应一个action identifier。action identifier 用标准的点分隔关键路径命名。一个layer负责去映射action identifier 给一个action object。当有identifier的action object 被找到时,发送在CAAction协议里定义的消息。

  CALayer类提供了一个默认的action object----CAAnimation实例,其是个兼容CAAction协议的类---对所有的可动画的layer属性。CALayer还定义了一些action triggers,这些没有直接联系到属性上。

action trigger 和对应的identifiers

Trigger

Action identifier

A layer is inserted into a visible layer-tree, or the hidden property is set to NO.

The action identifier constant kCAOnOrderIn.

A layer is removed from a visible layer-tree, or the hidden property is set to YES.

The action identifier constant kCAOnOrderOut.

A layer replaces an existing layer in a visible layer tree using replaceSublayer:with:.

The action identifier constant kCATransition.

2.定义action keys的搜索模式
   当一个action trigger发生时,layer的方法actionForKey:会被调用。此方法会返回一个与传入的action identifier参数对应的action object,如果没有存在的action object,则返回nil。

   当CALayer对于一个identifier实现actionForKey:,将使用下面的搜索模式:
(1)如果layer有代理,并且实现了方法actionForLayer:forKey:,此方法会被调用,传递的参数为layer和action identifier。代理应该遵循下面的情况去实现此方法。
  返回一个和action identifier对应的action object。
  如果不处理action identifier,则返回nil。
  如果不处理acttion identifier并且搜索应该被终止,则返回NSNull。

(2)查找layer的actions属性,此属性为一个字典,寻找对应于action identifier的对象。

(3)查找layer的style属性,此属性也为一个字典,寻找对应于action identifier的对象。

(4)layer类发送消息defaultActionForKey:,它会返回一个对应与action identifier的action object,没有发现则返回nil。