图层、视图anchorPoint position frame属性

/* 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));
    });

Original Article

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。