CALayer - 4
来源:互联网 发布:江西省网络作家协会 编辑:程序博客网 时间:2024/06/05 19:19
这一节来看看两个非常重要的属性:
/* 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;
/* 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;
看两个介绍就能大致知道意义:
position是锚点anchor point在super view 的点,而anchor point则是表示矩形中的一点,其范围是 ( 0 , 1),这个看文顶顶大神:
http://www.cnblogs.com/wendingding/p/3800736.html 的解释非常清楚,这里只讲解一些需要非常注意的地方
尤其注意,layer.position 是通过自己来指定superView的位置,而不是父层来指定子层的位置。所以position是不用提前计算的,你的subLayer添加在图层上的时候开始计算了!!这个可以自己输出看看!!
上面文顶顶大神例子我觉得还是不够贴切,这里用这个小伙伴的例子:
http://blog.163.com/it__man/blog/static/137199904201532345449/
UIView* vview = [UIView new]; [vview setFrame:CGRectMake(0, 0, 200, 100)]; //可以试下,bounds,如果使用bounds你怎么变都木有效果的呢 //[vview setBounds:CGRectMake(0, 0, 200, 100)]; [vview setBackgroundColor:[UIColor greenColor]]; [self.view addSubview:vview];
设置anchorpoint:
UIView* vview = [UIView new]; [vview setFrame:CGRectMake(0, 0, 200, 100)]; //可以试下,bounds,如果使用bounds你怎么变都木有效果的呢 //[vview setBounds:CGRectMake(0, 0, 200, 100)]; [vview setBackgroundColor:[UIColor greenColor]]; [self.view addSubview:vview]; [vview.layer setAnchorPoint:CGPointZero];
如果我们要恢复原来的就只要通过green layer设置superview的position:
UIView* vview = [UIView new]; [vview setFrame:CGRectMake(0, 0, 200, 100)]; //可以试下,bounds,如果使用bounds你怎么变都木有效果的呢 //[vview setBounds:CGRectMake(0, 0, 200, 100)]; [vview setBackgroundColor:[UIColor greenColor]]; [self.view addSubview:vview]; [vview.layer setAnchorPoint:CGPointZero]; vview.layer.position = CGPointMake(0, 0);
非常好理解吧!
但是其实要彻底理解这个概念其实要结合Frame anchorPoint Position来理解。
将在下一篇详细总结。
0 0
- CALayer - 4
- CALayer 自定义层-4
- CALayer Mask - 4 - CAGradientLayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- CALayer
- 常见的Java不规范代码
- 第二章 基本程序设计
- <LeetCode OJ> 136 / 137 / 260 Single Number(I / II / III)
- Bootstrap表单(二)
- 第1章 JavaScript简介小结
- CALayer - 4
- 第2章 在HTML中使用JavaScript小结
- 文档滚动对 scrollTop scrollLeft的兼容性封装
- 【C++】深度探索C++对象模型之Function语意学
- C或C++文件操作大全
- 4、C语言与画面显示的练习
- 设计模式之观察者设计模式
- 第3章 基本概念小结
- 新年寄语