CALayer的anchorPoint和position

来源:互联网 发布:sql查询去除重复行 编辑:程序博客网 时间:2024/05/22 23:59

创建layer

-(void)createLayer{    CALayer * calayer = [CALayer layer];    calayer.backgroundColor = [UIColor cyanColor].CGColor;    calayer.bounds = CGRectMake(0, 0, 100, 100);    calayer.position = CGPointMake(100, 100);    calayer.anchorPoint = CGPointMake(0.5, 0.5);//默认    calayer.masksToBounds = YES;    calayer.contents =(id)[UIImage imageNamed:@"1"].CGImage;//    calayer.cornerRadius = 20;//    calayer.borderColor = [UIColor redColor].CGColor;//    calayer.borderWidth = 5;    [self.view.layer addSublayer:calayer];}

position决定layer在父视图上面的位置,而anchorPoint决定layer上哪个点是position的点。
1
2
3

0 0