文章摘要: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的区别
闲话不多说,先上两张图,大伙们就已经明白了: 显示出来的效果是这样子滴: 总结: 要理清这两者的区别,最主要的要理解一下几个概念:frame可以理解为可视的范围,而bounds可以理解为可视范围内的 ...
- iOS开发 frame 与 bounds 的区别与关系 转自隔叶黄莺
frame和bounds是UIView中的两个属性(property). frame指的是:该view在父view坐标系统中的位置和大小.(参照点是父亲的坐标系统) bounds指的是:该view在本 ...
- 【iOS】Frame和Bounds的区别以及获取绝对坐标的办法
终于搞清楚了,UIView中的frame获取的是相对于所在ParentView的坐标,而bounds则是指UIView本身的坐标.比如下图(假设A是屏幕): View B的Frame坐标是指相对于Vi ...
- iOS开发-View中frame和bounds区别
开发中调整View的时候的经常会遇到frame和bounds,刚开始看的时候不是很清楚,不过看了一下官方文档,frame是确定视图在父视图中的位置,和本身的大小,bounds确定可以确定子视图在当前视 ...
- iOS View的Frame和bounds之区别,setbounds使用(深入探究)
前言: 在ios开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bound的区别,尤其是bound很绕,较难理解. 一.首先,看一下公认的资料: 先看到下面的代码你肯定就明白了一 ...
- ios基础之 view的frame 与 bounds 的区别 (转)
前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...
- ios view的frame和bounds之区别(位置和大小)
前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...
- 深入探究frame和bounds的区别以及setbounds使用
[转自]http://blog.csdn.net/hherima/article/details/39501857 在iOS开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bou ...
- iOS开发frame, contentSize, contentOffset, contentInset 区别联系浅析
1. 概述 iOS开发中,必然会涉及到布局相关问题,frame,bounds,contenSize,contentOffset,contentInset这几个布局相关概念让许多初学者感到困惑.虽然初步 ...
随机推荐
- FZU2143Board Game(最小费用流)
题目大意是说有一个B矩阵,现在A是一个空矩阵(每个元素都为0),每次操作可以将A矩阵相邻的两个元素同时+1,但是有个要求就是A矩阵的每个元素都不可以超过K,求 这个的最小值 解题思路是这样的,新建起点 ...
- HDU 3696 Farm Game(dp+拓扑排序)
Farm Game Problem Description “Farm Game” is one of the most popular games in online community. In t ...
- 转载:linux vi命令详解
转自:http://www.cnblogs.com/mahang/archive/2011/09/01/2161672.html 刚开始学着用linux,对vi命令不是很熟,在网上转接了一篇. vi编 ...
- 11.聚合(Aggregation)
聚合关系是关联关系的一种特例,它体现的是整体与部分的关系,即has-a的关系,此时整体与部分之间是可分离的,它们可以具有各自的生命周期.比如计算机与CPU.公司与员工的关系等.表现在代码层面,和关联关 ...
- 使用MySQL中的EXPLAIN解释命令来检查SQL
我们看到许多客户的系统因为SQL及数据库设计的很差所以导致许多性能上的问题,这些问题不好解决,但是可以采用一套简单的策略来检查生产系统,发现并纠正一些共性问题. 很显然,您应该尽最大努力设计出最好的数 ...
- Java 打印堆栈的几种方法
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- UVALive 4225 Prime Bases 贪心
Prime Bases 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&a ...
- 大话设计模式C++实现-第22章-桥接模式
一.UML图 二.概念 桥接模式(Bridge):将抽象部分与它的实现部分分离,使他们都能够独立地变化. 三.说明 为什么叫"桥接模式"? 如上所看到的的UML图中,有一个聚合线, ...
- 微信公共服务平台开发(.Net 的实现)13-------网页授权(下 :C#代码的实现 )
接着上次的理论,我们这次来研究用代码实现“网页授权获取用户基本信息”,首先我们需要一个链接指向微信的授权页面,在微信开发平台中已经说了,这个链接必须在微信客户端中打开,那么我们就干脆使用文本消息来完成 ...
- 在Android应用中实现Google搜索的例子
有一个很简单的方法在你的 Android 应用中实现 Google 搜索.在这个例子中,我们将接受用户的输入作为搜索词,我们将使用到 Intent.ACTION_WEB_SEARCH . Google ...