Core animation 学习笔记

图层
  1. 每一个UIView都有一个CALayer
    1.  改变UIView里Layer的frame,bounds,backgroundColor都会影响UIView
  2. 添加到父图层的子图层,当只设置bounds时.
    1. position为 {0,0} 
    2. anchorPoint为{0.5,0.5} 子图层的中心位置
      1.     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);
      2. 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}
    3. anchorPoint可以当做一个拨动一个图层手柄,默认为它处于图层的中心位置{0.5,0.5},的改变anchorPoint会改变Layer在父图层上的坐标.
    4. 直接对layer的frame,bounds,position做赋值,会触发一个隐式动画,时长为默认的0.25秒.(root layer没有)
     
绘制
  1. CALayer可以通过delegate代理函数- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx和重载- (void)display来进行绘制内容
    1. 一般采用CGContextXXX函数集来进行绘制(由于不属于cocoa,所以在处理XXXCreateXXX函数时,需要手动释放内存CFRelease)
    2. 也可以通过赋值contents属性,来显示一张图片内容

动画
  1. 显示动画
    1. 它是由以下几个类来完成,如图
      1. 常用的有CAAnimationGroup,组合多个图层的动画
      2. CABasicAnimation,一般使用在位置,缩放,旋转
      3. CAKeyframeAnimation 一般针对一个图层关键帧操作,也就是一段时间连续多个不同的动作
      4. CATransition 主要做为隐式动页面转场动画,如淡入淡出,推入,翻滚,四个方向滑入,收缩,抽走
    2. UIView也提供了一些快捷的动画方式
      1. + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animationscompletion:(void (^)(BOOL finished))completion

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值