• iOS position(位置)和anchorPoint(锚点)


    参考自:

    https://www.jianshu.com/p/0dfccd073ae0

    https://www.cnblogs.com/kingbo/p/7162364.html

     

        CALayer *MamiLayer = [CALayer layer];
        MamiLayer.backgroundColor = [UIColor orangeColor].CGColor;
        MamiLayer.bounds = CGRectMake(0, 0, 100, 100);
        MamiLayer.position = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height /2);
        MamiLayer.anchorPoint=CGPointMake(0, 1);
        [self.view.layer addSublayer:MamiLayer];
        NSLog(@"MamiLayer.position =>( %f,%f )",MamiLayer.position.x,MamiLayer.position.y);
        
        CALayer *MamiLayer2 = [CALayer layer];
            MamiLayer2.backgroundColor = [UIColor redColor].CGColor;
            MamiLayer2.bounds = CGRectMake(0, 0, 100, 100);
            MamiLayer2.position = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height /2);
        //    MamiLayer.anchorPoint=CGPointMake(0.3, 0.3);
            [self.view.layer addSublayer:MamiLayer2];
    

    1. position相当于UIView视图中的center,是layer视图的中心点。

    2. 确实设置了anchorPoint , position 是不会改变的。

    3. 我的理解就是,设置anchorPoint在哪,就把anchorPoint 放到 position 的位置。就得到结果视图的位置。这是个逆推的过程。

    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    Microsoft office 2013安装图解
    6.2单一继承
    #include <QLabel>
    #include <QDebug>
    9.1运算符重载
    简单QT界面信号图形化输入输出
    类指针引用
    NULL和nullptr的区别
    网易云课堂_C语言程序设计进阶_第8周:图形交互程序
    5.3友元函数
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/12787309.html
Copyright © 2020-2023  润新知