CALayer 的属性分析(几何及图层关系属性)
2017-03-10 16:04
246 查看
/** 先列举CALayer的属性(几何及图层关系属性) **/
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的几个属性,后续会补上
/** 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的几个属性,后续会补上
相关文章推荐
- Core Animation图层的几何属性
- ArcGIS教程:打开网络分析“图层属性”对话框
- 产品属性数据关系分析
- UIView 简介(六)视图几何结构和坐标系统 包括frame, bounds和center属性之间的关系
- 文字与图片渐变效果(图层CALayer与属性蒙版mask )
- CALayer属性position和anchorPoint的关系
- UIVie和CALayer属性对应关系
- IOS开发图层CALayer的基本属性使用
- 正在预备Revit几何属性访问以及对象间关系的专题讲座
- iOS开发概述-13.UI控件图层属性CALayer
- 三层架构各层关系分析比较及其约定
- Tomcat中server.xml和web.xml相关属性的关系
- Window 中窗口的层次关系以及窗口的属性
- VSTS有Bug,分析数据库的维度和维度属性使用中文命名时候,作为报表参数会出错。虽然有解决办法但是头大。
- VSTS用Visio中UML工具进行分析设计与分布式系统设计器、类设计器的关系?
- 从算法的角度分析ERP、APS与MES的关系
- IDL中有继承关系的接口不应有重复的属性和方法
- 三层架构各层关系分析比较及其约定
- 实例分析CSS属性Display与Visibility不同
- Mediar.Framework—业务的实现3 (控制UI控件的可视和可编辑属性、验证、以及一对一,一对多,多对多关系)