position是anchortPoint在superlayer的点,就是当前视图的anchortPoint 在父视图上相当于position,就像bounds和frame的关系,position和anchortPoint相互独立,改变一个的值,另一个的值不会变,他们的关系是:
position.x = frame.origin.x + anchortPoint.x * bounds.x
因此改变一个的值只会改变frame的origin,如果这一个的值要重置frame回原来的值,否则会看不到视图的,举一个缩放的例子:按右上角锚点缩放
view.frame = CGRectMake(0,0, 100, 100);
view.layer.anchorPoint = CGPointMake(1, 0);
// 设置完anchortPoint必须要重新设置fame,否则frame根据上边的等式frame会变
view.frame = CGRectMake(0,0, 100, 100);
view.alpha = 0;
// 必须先设置anchortPoint再设置affineTransform,affineTransform是设置transform,
而transform是应用在anchorPoint上的,如果anchorPoint改变,必须重新设置transform
view.layer.affineTransform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:1 animations:^{
view.alpha = 1;
view.layer.affineTransform = CGAffineTransformMakeScale(1, 1);
}];