读到一篇讲UIView frame 实现的博客, 对相关知识进行了一个总结
https://mp.weixin.qq.com/s/ImYWnDeq4gG_gUkL3_ZDgw
view的frame计算要牢记几点, 计算公式如下:
frame.origin.x = position.x - anchorPoint.x * bounds.size.width;
frame.origin.y = position.y - anchorPoint.y * bounds.size.height;
anchorPoint 是视图的锚点, 在视图进行变换(平移,旋转)的, 作为一个支点.
anchorPoint 和 position 是同一个点, 前者是在layer层的位置, 后者是在父类坐标系的位置.
要记住的就是设置frame会隐式修改position,而默认的anchorPoint从来不会被隐式修改,只能被显式修改。
参考文章:
http://wonderffee.github.io/blog/2013/10/13/understand-anchorpoint-and-position/
https://zsisme.gitbooks.io/ios-/content/chapter3/anchor.html