iOS开发中CAlayer层的属性以及自定义层的方法

2020-01-14 17:45:27于海丽
易采站长站为您分析iOS开发中CAlayer层的属性以及自定义层的方法,代码基于传统的Objective-C,需要的朋友可以参考下  

CAlayer层的属性
一、position和anchorPoint

1.简单介绍

CALayer有2个非常重要的属性:position和anchorPoint

@property CGPoint position;

用来设置CALayer在父层中的位置

以父层的左上角为原点(0, 0)

@property CGPoint anchorPoint;

称为“定位点”、“锚点”

决定着CALayer身上的哪个点会在position属性所指的位置

以自己的左上角为原点(0, 0)

它的x、y取值范围都是0~1,默认值为(0.5, 0.5)

2.图示

anchorPoint

它的取值为0~1

iOS开发中CAlayer层的属性以及自定义层的方法

红色图层的anchorPoint为(0,0)

iOS开发中CAlayer层的属性以及自定义层的方法

红色图层的anchorPoint为(0.5,0.5)

iOS开发中CAlayer层的属性以及自定义层的方法

红色图层的anchorPoint为(1,1)

iOS开发中CAlayer层的属性以及自定义层的方法