首页 > 其他 > 详细

Core Animation笔记(- Layer 基本属性)

时间:2019-04-13 16:40:38      阅读:109      评论:0      收藏:0      [点我收藏+]

一.Layer的基本属性

1. contents 图层内容默认为nil 可以指定一张图片作为内容展示

 self.layerView.layer.contents = (__bridge id)imag.CGImage;

2. contentsGravity 类似于contentMode的效果,

如kCAGravityCenter居中不拉伸,

  kCAGravityResize,自动缩放.

3. contentsScale 内容缩放因子,默认为1,一般都设置为屏幕的缩放

  self.layerView.layer.contentsScale = [UIScreen mainScreen].scale;

4. masksToBounds 超出图层边界的内容是否显示 true:不显示

5.阴影

  //shadow
    layer1.shadowOpacity = 0.5;
    layer1.shadowOffset = CGSizeMake(0, 4);
    layer1.shadowRadius = 3;
    layer1.shadowColor = [UIColor yellowColor].CGColor;
    CGMutablePathRef circlePath = CGPathCreateMutable();
    CGPathAddEllipseInRect(circlePath, NULL, layer1.bounds);
    //阴影路径
    layer1.shadowPath = circlePath;
    CFRelease(circlePath);

6.锚点 anchorPoint 默认为0.5 0.5

7.magnificationFilter(放大率过滤) 看下官方文档的解释: The circle on the left uses kCAFilterLinear and the circle on the right uses kCAFilterNearest.

 技术分享图片

8.光栅化   // 当shouldRasterize设成true时,开启shouldRasterize后,CALayer会被光栅化为bitmap,layer的阴影等效果也会被缓存到bitmap中,等下次使用时不会再重新去渲染了。实现圆角本身就是在做颜色混合(blending),如果每次页面出来时都blending,消耗太大,这时shouldRasterize = yes,下次就只是简单的从渲染引擎的cache里读取那张bitmap,节约系统资源

    btn2.layer.shouldRasterize = true;
    btn2.layer.rasterizationScale = [UIScreen mainScreen].scale;

9.   cornerRadius 圆角 

  borderColor 边框颜色

  borderWidth 边框宽度

10layer 代理

//只有单独使用layer的时候才有可能需要实现代理绘画,如果是uiview,layer代理是其本身,

//实现drawRect方法

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;

 

Core Animation笔记(- Layer 基本属性)

原文:https://www.cnblogs.com/cnman/p/10701572.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!