美文网首页
iOS中frame和bounds区别

iOS中frame和bounds区别

作者: 罗平油菜花 | 来源:发表于2018-12-13 16:22 被阅读0次

frame指的是:该view在父view坐标系统中的位置和大小。(参照点是父亲的坐标系统)

bounds指的是:该view在本身坐标系统中 的位置和大小。(参照点是本身坐标系统)

以下是代码,方便理解


UIView *superView = [[UIView alloc]initWithFrame:CGRectMake(20,20,200,200)];

    superView.backgroundColor = [UIColor redColor];

    [self.view addSubview:superView];

    NSLog(@"superView frame:%@========superView bounds:%@",NSStringFromCGRect(superView.frame),NSStringFromCGRect(superView.bounds));

    UIView*subView = [[UIView alloc]initWithFrame:CGRectMake(0,0,100,100)];

    subView.backgroundColor = [UIColor orangeColor];

    [superView addSubview:subView];

    NSLog(@"subView frame:%@========subView bounds:%@",NSStringFromCGRect(subView.frame),NSStringFromCGRect(subView.bounds));

控制台打印结果:


superView frame:{{20, 20}, {200, 200}}========superView bounds:{{0, 0}, {200, 200}}

subView frame:{{0, 0}, {100, 100}}========subView bounds:{{0, 0}, {100, 100}}

运行结果如图一

image

下面我们改变superView的bounds来看看子视图会发生什么变化。

我们在上面定义superView的时候,修改superView的bounds。


    [superView setBounds:CGRectMake(-20, -20,200,200)];

控制台打印结果:


  superView frame:{{20, 20}, {200, 200}}========superView bounds:{{-20, -20}, {200, 200}}

 subView frame:{{0, 0}, {100, 100}}========subView bounds:{{0, 0}, {100, 100}}

运行结果如图二

image

我们在改变父视图的bounds的时候,子视图必将受影响。因为子视图的frame是根据父视图的bounds来确定的。

希望能帮助到你。

Best regards

Roger

相关文章

  • iOS 面试题目

    1、iOS frame和Bounds 以及frame和bounds区别2、 ios webView 加载HTML字...

  • iOS纪录

    (1)View的Frame与Bounds区别 摘自 ios view的frame和bounds之区别(位置和大小)...

  • iOS中frame和bounds区别

    frame指的是:该view在父view坐标系统中的位置和大小。(参照点是父亲的坐标系统) bounds指的是:该...

  • frame和bounds的区别

    在iOS中我们会经常遇到frame和bounds,这两个概念很相似,但是也有区别。frame还好理解,但是boun...

  • Frame和bounds的区别

    在iOS中我们会经常遇到frame和bounds,这两个概念很相似,但是也有区别。frame还好理解,但是boun...

  • frame和bounds的区别

    在iOS中我们会经常遇到frame和bounds,这两个概念很相似,但是也有区别。frame还好理解,但是boun...

  • 深入探究frame和bounds的区别以及setbounds使用

    深入探究frame和bounds的区别以及setbounds使用 深入探究frame和bounds的区别以及set...

  • UIView的frame和bounds的区别

    UIView的frame和bounds的区别 UIView作为iOS里面常用的控件,它有两个属性Frame和bou...

  • ios frame和bounds区别

    在开发中经常使用这两个属性,但是一直没有去真正理解,导致了好多情况把自己弄晕了,所以这次决定,花点时间去查一下,两...

  • 深入探究frame和bounds的区别以及setbounds使用

    在iOS开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bound的区别,尤其是bound很...

网友评论

      本文标题:iOS中frame和bounds区别

      本文链接:https://www.haomeiwen.com/subject/hrjbhqtx.html