首先明確UIView的frame屬性是由center和bounds屬性計(jì)算得到的东羹。
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下級結(jié)構(gòu)的CALayer呢税迷?
CALayer的position(相當(dāng)于center),bounds,anchorPoint是什么關(guān)系呢蕴茴?
雖然沒有frame十嘿,但是CALayer的顯示(虛擬frame)也是由這些組件算出來的
frame.origin.x = position.x - anchorPoint.x * bounds.size.width/2.0;
frame.origin.y = position.y - anchorPoint.y * bounds.size.height/2.0;
frame.size = bounds.size;
所以,當(dāng)我們在上面修改anchorPoint的時候屈嗤,實(shí)際上修改了顯示的運(yùn)算元素潘拨!
在Apple doc對frame的描述中有這么一句話:
Layers have an implicit frame that is a function of the position, bounds, anchorPoint, and transform properties.
When you specify the frame of a layer, position is set relative to the anchor point. When you specify the position of the layer, bounds is set relative to the anchor point.
【譯】layers 有一個由position, bounds, anchorPoint, and transform properties作用生成的隱式的frame
可以看到我們推導(dǎo)的公式基本符合這段描述,只不過還缺少了transform饶号,加上transform的話就比較復(fù)雜铁追,這里就不展開講了。