CALayer anchorPoint
来源:互联网 发布:网页美工图片 编辑:程序博客网 时间:2024/06/12 18:31
每当修改一个CALayer的anchorPoint属性时,都要重新设置CALayer的position坐标
1.CALayer *layer = [myView layer];
1. CALayer *layer = [myView layer];
2. CGPoint oldAnchorPoint = layer.anchorPoint;
3. [layer setAnchorPoint:CGPointMake(1.0, 1.0)];
4. [layer setPosition:CGPointMake(layer.position.x + layer.bounds.size.width * (layer.anchorPoint.x - oldAnchorPoint.x), layer.position.y + layer.bounds.size.height * (layer.anchorPoint.y - oldAnchorPoint.y))];
为什么呢?
首先要清楚,UIView的frame属性是由center和bounds属性计算得到的。
frame.origin.x = center.x - bounds.size.width/2.0;
frame.origin.y = center.y - bounds.size.height/2.0;
frame.size = bounds.size;
相对的,身为UIView下级结构的CALayer呢?
CALayer的position(相当于center),bounds,anchorPoint是什么关系呢?
虽然没有frame,但是CALayer的显示(虚拟frame)也是由这些组件算出来的
frame.origin.x = position.x - anchorPoint.x * bounds.size.width/2.0;
frame.origin.y = position.y - anchorPoint.x * bounds.size.height/2.0;
frame.size = bounds.size;
所以,当我们在上面修改anchorPoint的时候,实际上修改了显示的运算元素!这样当anchorPoint修改为(1.0,1.0)的时候,经过重新运算,CALayer向左上角移动了
0 0
- CALayer anchorPoint
- CALayer之anchorPoint分析
- CALayer之anchorPoint分析
- iOS- CALayer之position、anchorPoint
- CALayer的position和anchorPoint
- CALayer的position和anchorPoint
- CALayer和position和anchorPoint
- CALayer中的position与anchorPoint
- iOS-CALayer的anchorPoint锚点细解
- CALayer的position与anchorPoint
- CALayer的anchorPoint和position
- CALayer的anchorPoint属性与transform属性
- CALayer中anchorPoint和position的用法
- CALayer中anchorPoint和position的用法
- CALayer中anchorPoint和position的用法
- IOS CALayer中的position 和 anchorPoint
- 彻底理解CALayer的position与anchorPoint
- ios CALayer的Frame,bounds,position,anchorPoint
- PAT 乙级 1013. 数素数 (20)
- Android ViewPager 监听滑动
- Servlet&JSP (三)上传和下载
- MyBatid进阶(二)—缓存
- C语言实现快速翻转数组的顺序
- CALayer anchorPoint
- 解决nGrinder僵死任务的方案
- Linux中的find和grep命令
- Centos 6.6系统下安装Github
- CentOS7下安装Scrapy
- POJ3630Phone List[字典树]
- Android传感器(二):加速度传感器
- 航班代号及含义
- shell脚本收集