文章摘要: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. web.xml filter 顺序

    The order the container uses in building the chain of filters to be applied for a particular request ...

  2. Classifier4J的中文支持

    Classifier4J是一个轻量级的分类工具,支持贝叶斯分类.向量空间模型.信息摘要等.然而它却不支持中文,异常信息大致如下: Exception in thread "main" ...

  3. Kafka学习记录

    1 Kafka的基本介绍 Apache Kafka是分布式发布-订阅消息系统.它最初由LinkedIn公司开发,之后成为Apache项目的一部分.具有快速.可扩展.分布式.可复制等特点.Kafka与传 ...

  4. 6 种CSS设置居中的方法

    原文 Demos of each of the methods below by clicking here. Horizontal centering with css is rather easy ...

  5. android 弹出日期选择框

    DatePickerDialog 在很多时候需要用户去设定时间,不可能让用户去在一个文本框中去输入时间,所以就需要有个日期弹出选择框,而这个框就是DatePickerDialog. 1.在API中的D ...

  6. C:数组

    数组.排序 关于排序 :参考 关于数组: 参考 求a[i][j]行与列的和然后求平均值 参考 二维数组使用指针的表示方法  参考 字符串数组:char  name [5][20] ={ {} , {} ...

  7. GetSafeHwnd()函数解释[转]

    当我们想得到一个窗口对象(CWnd的派生对象)指针的句柄(HWND)时,最安全的方法是使用GetSafeHwnd()函数,通过下面的例子来看其理由: CWnd *pwnd = FindWindow(“ ...

  8. DBCP连接池介绍

    DBCP连接池介绍 ----------------------------- 目前 DBCP 有两个版本分别是 1.3 和 1.4. DBCP 1.3 版本需要运行于 JDK 1.4-1.5 ,支持 ...

  9. IE6中奇数宽高的BUG

    一个外部的相对定位div,内部一个绝对定位的div(right:0), 如图: 可是在IE6下查看,却变成了right:1px的效果了: IE6还有奇数宽高的bug,解决方案就是将外部相对定位的div ...

  10. jquery 3D 标签云

    http://www.gbin1.com/technology/jquerynews/20111205tagcloudbyjquery/index.html 相关选项 zoom: 90 初始的缩放度  ...