UIView CALayer frame,position ,anchorPoint的关系

UIView的几何属性有 frame,bounds,center.
CALayer的几何属性有 frame,bounds,position,anchorPoint
UIView的frame是由bounds,center来共同决定的。CALaye的position和UIView的center是同一个东东。
frame代表了图层的外部座标(也就是在父图层上占据的空间),bounds是内部座标({0, 0}通常是图层的左上角),center和position都代表了相对于父图层anchorPoint所在的位置。

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向左上角移动了

发布了72 篇原创文章 · 获赞 25 · 访问量 35万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章