CALayer 的属性分析(几何及图层关系属性)

CALayer核心属性解析
本文详细解析了CALayer的关键属性,包括bounds、position、anchorPoint和frame等,并阐述了它们在视图层级关系中的作用机制。


/** 先列举CALayer的属性(几何及图层关系属性) **/

/** Geometry and layer hierarchy properties. **/

/* The bounds of the layer. Defaults to CGRectZero. Animatable. */

@property CGRect bounds;

/* The position in the superlayer that the anchor point of the layer's
 * bounds rect is aligned to. Defaults to the zero point. Animatable. */

@property CGPoint position;

/* The Z component of the layer's position in its superlayer. Defaults
 * to zero. Animatable. */

@property CGFloat zPosition;

/* Defines the anchor point of the layer's bounds rect, as a point in
 * normalized layer coordinates - '(0, 0)' is the bottom left corner of
 * the bounds rect, '(1, 1)' is the top right corner. Defaults to
 * '(0.5, 0.5)', i.e. the center of the bounds rect. Animatable. */

@property CGPoint anchorPoint;

/* The Z component of the layer's anchor point (i.e. reference point for
 * position and transform). Defaults to zero. Animatable. */

@property CGFloat anchorPointZ;

/* A transform applied to the layer relative to the anchor point of its
 * bounds rect. Defaults to the identity transform. Animatable. */

@property CATransform3D transform;

/* Unlike NSView, each Layer in the hierarchy has an implicit frame
 * rectangle, a function of the `position', `bounds', `anchorPoint',
 * and `transform' properties. When setting the frame the `position'
 * and `bounds.size' are changed to match the given frame. */

@property CGRect frame;

/* When true the layer and its sublayers are not displayed. Defaults to
 * NO. Animatable. */

@property(getter=isHidden) BOOL hidden;
  

1.bounds

  为了描述子视图在父视图中的位置,需要一套坐标体系,layer.bounds.origin 属性提供了这套坐标体系,子视图的 layer.postion 即是用来描述子视图在父视图 bounds.origin 坐标系中的位置。(bounds.origin同父视图左上角是重合的)




2.position 和 anchorPoint

  如1.中所说,子视图在父视图中的位置,是相对父视图的坐标系(左上角)决定的,即是 子视图的anchorPoint 与 父视图坐标系的关系,其值为position。

  而锚点用的是比例值,取值0~1,在子视图size范围内取,默认(0.5,0.5),例子如下图:


 如果如上图,position不变,改变锚点为(1.0,1.0)的话:


  So,  在父视图 bounds 确定后,子视图在父视图中的位置,是由 anchorPoint 和 position 共同确定的。


3.frame

  有了bounds描述一个视图世界中,视图的大小及视图与坐标系的关系(位置);并且有了anchorPoint和position用于描述子视图与父视图世界坐标系的关系(位置)。

  我们其实还需要一个量,用来描述视图的大小及视图与在父视图世界中的位置,这就是frame:

  frame.origin.x = position.x - anchorPoint.x * bounds.size.width;

  frame.origin.y = position.y - anchorPoint.y * bounds.size.height;

  frame.size = bounds.size;

  为啥又有了这么个东西,太深层次我还没去看,我觉得可能是为了用起来方便吧。。。

4.有关3D的几个属性,后续会补上

AI-PPT 一键生成 PPT:用户输入主题关键词,AI-PPT 可快速生成完整 PPT,涵盖标题、正文、段落结构等,还支持对话式生成,用户可在 AI 交互窗口边查看边修改。 文档导入转 PPT:支持导入 Word、Excel、PDF 等多种格式文档,自动解析文档结构,将其转换为结构清晰、排版规范的 PPT,有保持原文和智能优化两种模式。 AI-PPT 对话 实时问答:用户上传 PPT 或 PPTX 文件后,可针对演示内容进行提问,AI 实时提供解答,帮助用户快速理解内容。 多角度内容分析:对 PPT 内容进行多角度分析,提供全面视野,帮助用户更好地把握内容结构和重点。 多语言对话支持:支持多语言对话,打破语言障碍,方便不同语言背景的用户使用。 AI - 绘图 文生图:用户输入文字描述,即可生成符合语义的不同风格图像,如油画、水彩、中国画等,支持中英文双语输入。 图生图:用户上传图片并输入描述,AI - 绘图能够根据参考图和描述生成新的风格化图像,适用于需要特定风格或元素的创作需求。 图像编辑:提供如 AI 超清、AI 扩图、AI 无痕消除等功能,用户可以上传图片进行细节修改和优化,提升图片质量。 AI - 文稿 文案生成:能够根据用户需求生成多种类型的文章,如市场营销文案、技术文档、内部沟通内容等,提升文案质量和创作效率。 文章润色:对已有文章进行改善和优化,包括语言表达、逻辑连贯性、内容流畅度等方面,使文章更符合用户期望和风格。 文章续写:AI 技术理解文本语境,为用户提供新的想法、补充资料或更深层次的见解,帮助用户丰富文档内容。 AI - 医生 智能健康咨询:包括症状自查,用户输入不适症状,AI 结合病史等信息提供疾病可能性分析与初步建议;用药指导,支持查询药品适应症、禁忌症等,并预警潜在冲突;中医辨证,提供体质辨识与调理建议。 医学报告解读:用户上传体检报告
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值