标签:
彻底理解CALayer的position,anchorPoint属性 与UIView的frame 属性
1.position,anchorPoint两者都是CALayer的属性,都是CGPoint点
@property CGPoint position
@property CGPoint anchorPoint
从一个例子开始入手吧,想象一下,把一张A4白纸用图钉订在书桌上,如果订得不是很紧的话,白纸就可以沿顺时针或逆时针方向围绕图钉旋转,这时候图钉就起着支点的作用。我们要解释的anchorPoint就相当于白纸上的图钉,它主要的作用就是用来作为变换的支点,旋转就是一种变换,类似的还有平移、缩放!而position是钉子在墙上的位置!像UIView有superView与subView的概念一样,CALayer也有superLayer与layer的概念
frame.origin由position和anchorPoint共同决定
frame.origin.x = position.x - anchorPoint.x * bounds.size.width;
frame.origin.y = position.y - anchorPoint.y * bounds.size.height;
例如 frame为(10,10,100,100)
10 = y-0.5*100
10 = y-0.5*100
这时候layer的posion为(60,60) anchorPoint为(0,5,0,5);
position官方解释
/* The position in the superlayer that the anchor point of the layer‘s
* bounds rect is aligned to. Defaults to the zero point. Animatable. */
position是相对于superlayer的位置 默认为0
anchorPoint官方解释
/* Defines the anchor point of the layer‘s bounds rect, as a point in
* normalized layer coordinates - ‘(0, 0)‘ is the bottom left corner of
* the bounds rect, ‘(1, 1)‘ is the top right corner. Defaults to
* ‘(0.5, 0.5)‘, i.e. the center of the bounds rect. Animatable. */
anchorPoint是相对于自己的 默认(0.5,0.5)
CALayer的position,anchorPoint属性 与UIView的frame 属性
标签:
原文地址:http://www.cnblogs.com/junhuawang/p/position-anchorPoint-frame.html