CALayer *layer = [CALayer layer];
layer.frame = CGRectMake(100, 100, 100, 100);
layer.backgroundColor = [UIColor redColor].CGColor;
[self.view.layer addSublayer:layer];
CGPoint point = layer.frame.origin; // (CGPoint) point = (x = 100, y = 100)
CGPoint position = layer.position; // (CGPoint) position = (x = 150, y = 150)
CGPoint anc = layer.anchorPoint; // 是比例 (CGPoint) anc = (x = 0.5, y = 0.5)
CGSize size = layer.bounds.size; // (CGSize) size = (width = 100, height = 100)
layer.anchorPoint = CGPointMake(0.5, 0); // 修改了锚点的值
CGPoint point1 = layer.frame.origin; // (CGPoint) point1 = (x = 100, y = 150)
CGPoint position1 = layer.position; // (CGPoint) position1 = (x = 150, y = 150)
CGPoint anc1 = layer.anchorPoint; // 是比例 (CGPoint) anc1 = (x = 0.5, y = 0)
CGSize size1 = layer.bounds.size; // (CGSize) size1 = (width = 100, height = 100)
从上面的代码可以看出:frame.origin.x = position.x - anchorPoint.x * bounds.size.width;
frame 和 position 是父视图坐标参考,anchorPoint和bounds是视图本身坐标.