CALayerDelegate
包含以下几个方法其中 displayLayer 方法 和 drawLayer 方法如果全部实现的话只会走displayLayer,他们的执行顺序是
layerWillDraw->displayLayer/drawLayer->layoutSublayersOfLayer;
如果当前View 有多个Layer 的话 在这4个方法中 写的代码 会在每个layer中绘制。
- (void)displayLayer:(CALayer *)layer;
和上一个方法类似
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;
//开始绘制时候 执行
- (void)layerWillDraw:(CALayer *)layer
//最后执行
- (void)layoutSublayersOfLayer:(CALayer *)layer;
//再添加 或删除 layer 层的时候回调用这个方法 ,可以按照分类写动画
- (nullable id)actionForLayer:(CALayer *)layer forKey:(NSString *)event;
eg:
-(id)actionForLayer:(CALayer *)layer forKey:(NSString *)event
{
NSLog(@"actionForLayer %@",event);
CATransition *anim=nil;
if([event isEqualToString:@"onOrderIn"]){
anim=[CATransition animation];
anim.duration=2;
anim.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.type=@"cube";
anim.subtype=kCATransitionFromRight;
}
return anim;
}