UIView的frame和bounds区别
UIView的frame和bounds区别
iOS中,大家肯定对view和frame都不陌生,我们设置view在父view中的位置和大小时,只需要设置frame就可以了。
可能大家也有查过网上的一些资料,可能也会得知frame是相对于superview坐标系的,而bounds则相对于view自身的坐标系,但是frame究竟是怎样表示坐标的呢,其实这就和bounds有关了。
值得肯定的是frame.size 和bounds.size 肯定一样,但是UIView中,frame其实是不存储的,而是动态计算的,改变center,改变bounds大小,或者改变transfrom都可能会导致frame的改变。
UIView的frame是一个动态的,官方文档中有提到
// animatable. do not use frame if view is transformed since it will not correctly reflect the actual location of the view. use bounds + center instead.
@property(nonatomic)
CGRect frame;
大意是说,如果我们的view有transform,则frame不能反映其在父view中的实际位置,需要用bounds+center来反映。
假定我们的view没有transform。 每次我们设置frame时,则系统首先会设置
bounds.origin
= 0,0
bounds.size = frame.size
然后会继续设置
center.x
= frame.origin.x + frame.size.width / 2
center.y = frame.origin.y + frame.size.height / 2
也就是说 设置frame时,我们的bounds和center都会发生变化,但是view的位置是由center和bounds共同决定的,完全可以不依赖于frame。
每次我们访问frame时,其实也是通过center和bounds计算。
frame.size
= bounds.size
frame.origin.x = center.x - bounds.size.width / 2
frame.origin.y = center.y - bounds.size.height / 2
当然期间如果有transform,则会考虑到transfrom,比如大小缩小到0.9倍,则center不变,frame.size 变为 0.9倍,origin也会跟着变。 transform不会影响到view的bounds和center,但是会影响到frame。
版权声明:本文为博主原创文章,未经博主允许不得转载。
UIView的frame和bounds区别的更多相关文章
- ios开发之UIView的frame、bounds跟center属性的区别(附图)
博文暂时想到什么写什么,不顺理成章,不顺章成篇. 先看几个概念 坐标点Poit:向右侧为X轴正方向的值x,原点下侧为Y轴正方向的值y 大小Size:由宽度width和高度height构成,表示一个矩形 ...
- iOS--------坐标系统(UIView的frame、bounds跟center属性)
1.概要翻开ios官方开发文档,赫然发现上面对这三个属性的解释如下: frame:描述当前视图在其父视图中的位置和大小. bounds:描述当前视图在其自身坐标系统中的位置和大小. center:描述 ...
- 详解UIView的frame、bounds和center属性
From: http://ios.wpjam.com/2011/08/29/uiview-frame-bounds-center/ 1.概要 翻开ios官方开发文档,赫然发现上面对这三个属性的解释如下 ...
- frame和bounds区别
学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bound的 ...
- [UIKit学习]01.关于UIView,frame,bounds,center
UIView是Cocoa大多控件的父类,本身不带事件. UIView的常见用法 @property(nonatomic,readonly) UIView *superview; 获得自己的父控件对象 ...
- iOS开发-View中frame和bounds区别
开发中调整View的时候的经常会遇到frame和bounds,刚开始看的时候不是很清楚,不过看了一下官方文档,frame是确定视图在父视图中的位置,和本身的大小,bounds确定可以确定子视图在当前视 ...
- UIView的frame和bounds的含义
1.frame是该view相对于父view的坐标系中的位置和大小.(参照点是父view的坐标系) 2.bounds是该view相对于自己的坐标.(参照点是本身坐标系统) 3.uiresponder&l ...
- iOS 基础-----关于UIView 的 frame 与 bounds
首先,对于frame 大家都很熟悉,是当前view ,相对于其父视图view 的坐标,例如: UIView *view1 = [[UIView alloc] initWithFrame:CGRectM ...
- IOS之frame和bounds区别
用最简单的语言来解释就是:setFrame和setBounds都是为了把子view加载到父view上去,但设置的参数坐标系不同,setFrame是该view在父view坐标系统中的位置和大小,setB ...
随机推荐
- Html笔记(七)表单
表单标签: <form> 表单标签是最常用的标签,用于与服务器端的交互. <input>:输入标签:接受用户输入信息 其中type属性指定输入标签的类型 文本框 text:输入 ...
- codevs 3160 最长公共子串(SAM)
3160 最长公共子串 题目描述 Description 给出两个由小写字母组成的字符串,求它们的最长公共子串的长度. 输入描述 Input Description 读入两个字符串 输出描述 Ou ...
- Pascal's Triangle II
1.题目描述 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Re ...
- HW4.41
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- echarts 折线柱形上方显示自定义格式数据
series:[ { name: '成单率', type: 'line', data: valueArr2, itemStyle: { normal: { label: { show:true, po ...
- java中通过反射获取方法并且调用(getMethod和invoke深入)实践
为了支持业务的快速变更,往往采用可配置的方式,将业务逻辑的处理部分配置在数据库中或者XMl文件里.配置什么,如何配置才更灵活,That's a problem. 以数据库配置为例(xml相同),在数据 ...
- MVC模式网站编写经验总结
单个网站使用MVC架构模式经验总结,包含具体网站包分类.包内类的编写.注意事项等方面.本人认为,按照如下包分类及编写方法,已经满足一个简单普通网站(主要针对java)的编写需求. MVC主要层级 数据 ...
- AtomicLong
Spring package com.uniubi.management.controller; import java.util.concurrent.atomic.AtomicLong; impo ...
- java 5 Lock
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public clas ...
- java 5 线程池
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Thr ...