/* The position in the superlayer that the anchor point of the layer's
* bounds rect is aligned to. Defaults to the zero point. Animatable. */
根据定义,并且,通过这段实际代码,打印视图frame、position, 感受anchorPoint在iOS CALayer图层中的含义。通过调整各个值,观察运行界面效果,对比NSStringFromCGRect和NSStringFromCGPoint的打印结果。
与仿射变换缩放CGAffineTransformMakeScale同时操作,加深对anchorPoint理解。
UIView* aView = [[UIView alloc] init];
aView.backgroundColor = [UIColor blackColor];
UIView* bView = [[UIView alloc] init];
bView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:aView];
[aView addSubview:bView];
aView.layer.anchorPoint = CGPointMake(2, 2);
aView.frame = CGRectMake(100, 100, 100, 100);
aView.transform = CGAffineTransformMakeScale(1.5, 1.5);
bView.frame = CGRectMake(0, 0, 50, 50);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"aView的frame: %@",NSStringFromCGRect(aView.frame));
NSLog(@"aView的position: %@",NSStringFromCGPoint(aView.layer.position));
NSLog(@"bView的frame: %@",NSStringFromCGRect(bView.frame));
});