ios中图层的ancorPoint

@interface MJViewController () {
    CALayer *_layer;
}

@end

@implementation MJViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    CALayer *layer = [CALayer layer];
    layer.bounds = CGRectMake(0, 0, 100, 100);
    layer.position = CGPointMake(150, 150);
    layer.backgroundColor = [UIColor redColor].CGColor;
    
    // 定位点(1,1):当前图层右下角会在position所指定的位置上
//anchorPoint决定的Position的位置
layer.anchorPoint = CGPointMake(0, 0);//说明position的在左上角,坐标为(150,150) 宽度和高度分别100,100 _layer = layer; [self.view.layer addSublayer:layer]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { _layer.anchorPoint = CGPointMake(1, 1);//说明position的右下角坐标为(150,150) 宽度和高度为100,100. }
原文地址:https://www.cnblogs.com/gcb999/p/3189226.html