图层
- 每一个UIView都有一个CALayer
- 改变UIView里Layer的frame,bounds,backgroundColor都会影响UIView
- 添加到父图层的子图层,当只设置bounds时.
- position为 {0,0}
- anchorPoint为{0.5,0.5} 子图层的中心位置
- CALayer *subLayer = [CALayerlayer];
subLayer.backgroundColor = [UIColoryellowColor].CGColor;
subLayer.bounds = CGRectMake(0, 0, 30, 30);
subLayer.contents = (id)[UIImageimageNamed:@"snowman"].CGImage;
[self.redView.layeraddSublayer:subLayer];
PR(subLayer.bounds);
PP(subLayer.position);
PP(subLayer.anchorPoint); - 2015-09-09 22:10:18.571 Animation_practice[7328:472163] rect = {{0, 0}, {30, 30}}
2015-09-09 22:10:18.572 Animation_practice[7328:472163] point = {0, 0}
2015-09-09 22:10:18.572 Animation_practice[7328:472163] point = {0.5, 0.5}
- CALayer *subLayer = [CALayerlayer];
- anchorPoint可以当做一个拨动一个图层手柄,默认为它处于图层的中心位置{0.5,0.5},的改变anchorPoint会改变Layer在父图层上的坐标.
- 直接对layer的frame,bounds,position做赋值,会触发一个隐式动画,时长为默认的0.25秒.(root layer没有)
绘制
- CALayer可以通过delegate代理函数- (void)drawLayer:(CALayer *)
layer
inContext:(CGContextRef)ctx和重载
- (
void
)display来进行绘制内容
- 一般采用CGContextXXX函数集来进行绘制(由于不属于cocoa,所以在处理XXXCreateXXX函数时,需要手动释放内存CFRelease)
- 也可以通过赋值contents属性,来显示一张图片内容
动画
- 显示动画
- 它是由以下几个类来完成,如图
- 常用的有CAAnimationGroup,组合多个图层的动画
- CABasicAnimation,一般使用在位置,缩放,旋转
- CAKeyframeAnimation 一般针对一个图层关键帧操作,也就是一段时间连续多个不同的动作
- CATransition 主要做为隐式动页面转场动画,如淡入淡出,推入,翻滚,四个方向滑入,收缩,抽走
- UIView也提供了一些快捷的动画方式
- + (void)animateWithDuration:(NSTimeInterval)
duration
delay:(NSTimeInterval)delay
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
- + (void)animateWithDuration:(NSTimeInterval)
- 它是由以下几个类来完成,如图