美文网首页
layer的anchor和position

layer的anchor和position

作者: 请叫我魔法师 | 来源:发表于2017-08-05 11:08 被阅读0次

链接:写的好。看明白了。http://kittenyang.com/anchorpoint/
再复制一下结论。

anchorPoint.png

总结
1、position是layer中的anchorPoint在superLayer中的位置坐标,其实就是没改变frame前的中心点。
2、anchorPoint是相对自身layer坐标系中的位置,坐标系如图。
2、互不影响原则:单独修改position与anchorPoint中任何一个属性都不影响另一个属性。
3、frame、position与anchorPoint有以下关系:
frame.origin.x = position.x - anchorPoint.x * bounds.size.width;
frame.origin.y = position.y - anchorPoint.y * bounds.size.height;

我的理解:狗尾续貂:通过这个公式可以看到position和anchor的修改都影响frame,但不影响对方。如果需要修改,但不影响frame,可以再把frame赋值成原来的值。

相关文章

网友评论

      本文标题:layer的anchor和position

      本文链接:https://www.haomeiwen.com/subject/louilxtx.html