文章摘要:http://www.sendong.com/news1733.html
bounds是指这个view在它自己坐标系的坐标和大小 而frame指的是这个view在它superview的坐标系的坐标和大小
区别主要在坐标系这一块。

很明显一个是自己为原点的坐标系,一个是以屏 幕为原点的坐标系。绝对坐标。。。相对坐标。。。比如屏幕旋转的时候就要以相对来重绘。 
frame 如果一个按钮,是在表格里,按钮的frame 的坐标也是相对的,并不是相对屏幕,也就是说是相对坐标,不是绝对坐标

我也想知道任何一个uiview如何求得它在屏幕上的坐标。


view 的frame是view在它的super view 的位置与尺寸。
view
的bounds可以用来帮助它的subview来定位的 ,layoutSubviews。

Frame  is  in  terms  of
superview's  coordinate  system   

框架是从父视图的坐标系统


Bounds   is in  terms
 of   local  coordinate  system
是在局部坐标系统。
frame和bounds是UIView中的两个属性(property)。
frame指的是:该view在父view坐标系统中的位置和大小。(参照点是父亲的坐标系统)
bounds指的是:该view在本身坐标系统中 的位置和大小。(参照点是本身坐标系统)
ios视图frame和bounds的区别:
bounds坐标:自己定义的坐标系统,setbound指明了本视图左上角在该坐标系统中的坐标,
        默认值(0,0)
frame坐标:  子视图左上角在父视图坐标系统(bounds坐标系统)中的坐标,默认值(0,0)
子视图实际位置=父视图实际位置-父视图bounds坐标+子视图frame坐标
一、bounds
  只影响“子视图”相对屏幕的位置,修改时不会影响自身相对屏幕的位置
1、父视图bounds坐标为(0,0)时
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
}
2、父视图bounds坐标为(-20,-20)时 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    [self.view setBounds:CGRectMake(-20, -20, 320, 568)];
    
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
二、frame
  修改时改变了自己的在父视图坐标系统(bounds坐标系统)的位置,自身位置和
  子视图位置都会被改变。
1、父视图frame坐标(0,0)
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 260)];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    view2.backgroundColor = [UIColor yellowColor];
    [view1 addSubview:view2];
    
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(view1.frame),NSStringFromCGRect(view1.bounds));
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(view2.frame),NSStringFromCGRect(view2.bounds));
} 
2、父视图frame坐标(60,60)
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(60, 60, 200, 260)];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    view2.backgroundColor = [UIColor yellowColor];
    [view1 addSubview:view2];
    
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(view1.frame),NSStringFromCGRect(view1.bounds));
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(view2.frame),NSStringFromCGRect(view2.bounds));
三、说明
  根视图只能修改bounds坐标,而不可以修改frame坐标
  以下self.view为根视图
1、初始状态
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
2、修改bounds坐标:有效
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    CGRect viewBounds = self.view.bounds;
    viewBounds.origin.y=-40;
    viewBounds.origin.x=-40;
    self.view.bounds=viewBounds;
    
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
3、修改frame坐标:无效
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    CGRect viewFrame = self.view.frame;
    viewFrame.origin.y=60;
    viewFrame.origin.x=60;
    self.view.frame=viewFrame;
    
    NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));

IOS 中frame与bounds的区别的更多相关文章

  1. iOS开发中frame与bounds的区别

    闲话不多说,先上两张图,大伙们就已经明白了: 显示出来的效果是这样子滴:  总结: 要理清这两者的区别,最主要的要理解一下几个概念:frame可以理解为可视的范围,而bounds可以理解为可视范围内的 ...

  2. iOS开发 frame 与 bounds 的区别与关系 转自隔叶黄莺

    frame和bounds是UIView中的两个属性(property). frame指的是:该view在父view坐标系统中的位置和大小.(参照点是父亲的坐标系统) bounds指的是:该view在本 ...

  3. 【iOS】Frame和Bounds的区别以及获取绝对坐标的办法

    终于搞清楚了,UIView中的frame获取的是相对于所在ParentView的坐标,而bounds则是指UIView本身的坐标.比如下图(假设A是屏幕): View B的Frame坐标是指相对于Vi ...

  4. iOS开发-View中frame和bounds区别

    开发中调整View的时候的经常会遇到frame和bounds,刚开始看的时候不是很清楚,不过看了一下官方文档,frame是确定视图在父视图中的位置,和本身的大小,bounds确定可以确定子视图在当前视 ...

  5. iOS View的Frame和bounds之区别,setbounds使用(深入探究)

    前言: 在ios开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bound的区别,尤其是bound很绕,较难理解. 一.首先,看一下公认的资料: 先看到下面的代码你肯定就明白了一 ...

  6. ios基础之 view的frame 与 bounds 的区别 (转)

    前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...

  7. ios view的frame和bounds之区别(位置和大小)

    前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...

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

    [转自]http://blog.csdn.net/hherima/article/details/39501857 在iOS开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bou ...

  9. iOS开发frame, contentSize, contentOffset, contentInset 区别联系浅析

    1. 概述 iOS开发中,必然会涉及到布局相关问题,frame,bounds,contenSize,contentOffset,contentInset这几个布局相关概念让许多初学者感到困惑.虽然初步 ...

随机推荐

  1. [转载]开机出现A disk read error occurred错误

    [此文章转载] 今天维修了一台机器,郁闷之极.最开始一直无法正确安装操作系统,一安装总是提示文件无法写入内存.换了光盘.光驱都无济于事,忽然意识到是不是内存的问题,随即找了一个内存来,替换了一下,更郁 ...

  2. Python基础-函数(function)

    这里我们看看Python中函数定义的语法,函数的局部变量,函数的参数,Python中函数的形参可以有默认值,参数的传递是赋值操作,在函数调用时,可以对实参进行打包和解包  1,函数定义 关键字def引 ...

  3. svg base64

    好多h5页面有出现data:image/png;base64,后面跟了一串类似乱码的字母 查了下原来这也是svg或者是图片 <img src=“data:image/png;base64,iVB ...

  4. Codeforces 583D. Once Again... (LIS变形)

    题目链接:http://codeforces.com/contest/583/problem/D 给你t个长度为n的数组.问你最长不下降子序列的长度. 一开始用第一个n数组的lis和最后一个n数组的l ...

  5. DevExpress控件使用经验总结

    转自:http://www.cnblogs.com/wuhuacong/archive/2011/08/31/2161002.html

  6. MRI中T1和T2的含义与区分[转]

    A. MRI名词解释   T1加权像.T2加权像为磁共振检查中报告中常提到的术语,很多非专业人士不明白是什么意思,要想认识何为T1加权像.T2加权像,请先了解几个基本概念:   1.磁共振(maget ...

  7. vtk读取文件中点坐标[转]

    vtk基础编程(2)-读取数据文件中的坐标点 1. 案例说明 在实际计算中,常常需要大量的数据, 这个时候数据文件就必不可少, 例如 数据文件points.dat, 中存放了三个点的坐标, 0.0 0 ...

  8. (剑指Offer)面试题35:第一个只出现一次的字符

    题目: 在字符串中找出第一个只出现1次的字符,如输入“abaccdeff”,则输出b. 思路: 1.暴力遍历 从头开始扫描字符串中的每个字符,当访问某个字符时,取该字符与后面的每个字符相比较,如果没有 ...

  9. START167 AND BOOT167

    http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka10535.html C166: START167 AND BOO ...

  10. Binary Search

    Binary Search                              [原文见:http://www.topcoder.com/tc?module=Static&d1=tuto ...