首页 > 其他 > 详细

说说anchorPoint

时间:2016-05-17 07:27:17      阅读:225      评论:0      收藏:0      [点我收藏+]

anchorPoint属性是CGPoint(x,y) ,x,y的取值是按比例取值,一般用0~1,默认是(0.5,0.5),表示图层的position在自身的位置,举个例子,

技术分享

技术分享

在红色view确定完大小位置后,如果修改layer的定位点也就是anchorPoint,会让红色view的中心点position发生偏移,此时的定位点在箭头指向的地方,anchorPoint的取值是layer左上角是(0,0),右下角是(1,1),layer的中心因为anchorPoint的改变而改变,anchorPoint参考左上角(1,1),右下角(0,0)来改变layer中心点的位置,本例中anchorPoint = (0.5,1),那么视图就会向上移动0.5个layer的height,此时anchorPoint在箭头所在位置, 

 

anchorPoint本质上就是个点,只是在视图frame先确定的情况下,会让layer的中心点改变,anchorPoint的取值是依托于layer的,

本题中如果先写v.layer.anchorPoint,后写v.frame,那么视图的中心不变,只是定位点的坐标发生了变化而已,因为定位点在layer位置不存在的时候没办法改变layer的中心点

说说anchorPoint

原文:http://www.cnblogs.com/mingdonghuaxia/p/5500172.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!