About View
View Geometry
Frame & Bounds
Graphically, a view can be regarded as a framed canvas. The frame locates the view in its superview, defines its size, and clips drawing to its edges, while the canvas hosts the actual drawing. The frame can be moved, resized, and rotated in the superview and the view's content moves with it. Similarly, the canvas can be shifted, stretched, and rotated, and the view contents move within the frame.
A view tracks its size and location using two rectangles: a frame rectangle and a bounds rectangle. The frame rectangle defines the view's location and size in the superview using the superview’s coordinate system. The bounds rectangle defines the interior coordinate system that is used when drawing the contents of the view, including the origin and scaling.
frame用于在其父view中使用父view的坐标系统中定义view的location 和 size。 Bounds定义一个内部的坐标系统,当绘制view的内容时,就要用这个坐标系统,也包括起点和缩放。
If the size of the bounds rectangle differs from the frame rectangle, the content is stretched or compressed so that all the contents within the bounds are displayed in the view.
Transforming the Coordinate System
By default, a view's coordinate system is based at (0.0, 0.0) in the lower-left corner of its bounds rectangle, its unit square (the size of a 1.0 by 1.0 rectangle) is the same size as those of its superview, and its axes are parallel to that of its frame rectangle. The coordinate system of a view can be changed in four distinct ways: It can be translated, scaled, flipped, or rotated.
To translate or scale the coordinate system, you alter the view's bounds rectangle. Changing the bounds rectangle sets up the basic coordinate system with which all drawing performed by the view begins. Concrete subclasses of NSView typically alter the bounds rectangle immediately as needed in their initWithFrame: methods or upon loading a nib file that contains the view.
The method for changing the bounds rectangle is setBounds:, which both positions and scales the canvas. The origin of the rectangle provided to setBounds: becomes the lower-left corner of the bounds rectangle, and the size of the rectangle is made to fit in the frame rectangle, effectively scaling the view's drawn image.
当改变了坐标系统后,需要调用setNeedsDisplay,将view设置为需要重新绘制,或者调用display立刻重新绘制view。
NSView objects marked as needing display are automatically redisplayed on each pass through the application’s event loop. (View objects that need to redisplay before the event loop comes around can of course immediately be sent the appropriate display... method.)
参考文档:
About View的更多相关文章
- 虾扯蛋:Android View动画 Animation不完全解析
本文结合一些周知的概念和源码片段,对View动画的工作原理进行挖掘和分析.以下不是对源码一丝不苟的分析过程,只是以搞清楚Animation的执行过程.如何被周期性调用为目标粗略分析下相关方法的执行细节 ...
- MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信
MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...
- Android 判断一个 View 是否可见 getLocalVisibleRect(rect) 与 getGlobalVisibleRect(rect)
Android 判断一个 View 是否可见 getLocalVisibleRect(rect) 与 getGlobalVisibleRect(rect) [TOC] 这两个方法的区别 View.ge ...
- android 使用Tabhost 发生could not create tab content because could not find view with id 错误
使用Tabhost的时候经常报:could not create tab content because could not find view with id 错误. 总结一下发生错误的原因,一般的 ...
- SAP CRM 树视图(TREE VIEW)
树视图可以用于表示数据的层次. 例如:SAP CRM中的组织结构数据可以表示为树视图. 在SAP CRM Web UI的术语当中,没有像表视图(table view)或者表单视图(form view) ...
- 深入理解 Android 之 View 的绘制流程
概述 本篇文章会从源码(基于Android 6.0)角度分析Android中View的绘制流程,侧重于对整体流程的分析,对一些难以理解的点加以重点阐述,目的是把View绘制的整个流程把握好,而对于特定 ...
- Android listview和gridview以及view的区别
GridView 可以指定显示的条目的列数. listview一般显示的条目的列数都是一列 如果是列表(单列多行形式)的使用ListView,如果是多行多列网状形式的优先使用GridView andr ...
- mono for android Listview 里面按钮 view Button click 注册方法 并且传值给其他Activity 主要是context
需求:为Listview的Item里面的按钮Button添加一个事件,单击按钮时通过事件传值并跳转到新的页面. 环境:mono 效果: 布局代码 主布局 <?xml version=" ...
- Android中自定义样式与View的构造函数中的第三个参数defStyle的意义
零.序 一.自定义Style 二.在XML中为属性声明属性值 1. 在layout中定义属性 2. 设置Style 3. 通过Theme指定 三.在运行时获取属性值 1. View的第三个构造函数的第 ...
- 简单例子了解View的事件分发
什么是事件分发 我们在写自定义ViewGroup或者自定义View的时候经常要处理用户的点击事件,如果我们的View在最底层,他在很多ViewGroup里面,我们如何让我们的点击事件准确传递到View ...
随机推荐
- The Network Adapter could not establish the connection问题研究
最近一个项目会报上述错误,但也不是经常发生,所以很难跟踪,影响不是很大,但每次看到日志中这个错误就会不舒服,还是要想办法解决才是. 错误提示信息很明确是网络适配器不能创建连接. 查了很多资料,并且Or ...
- PC上安装多个操作系统
目 录 第1章 绪论 1 1.1 目标 1 1.2 适宜的读者 1 第2章 制作启动U盘 2 2.1 初级安装 2 2.2 启动分析 3 2.3 高级安装 1 ...
- java 集合4(迭代器)
迭代器使用要注意的问题: 1.迭代器在遍历元素的时候注意事项: 在迭代器迭代元素的过程中,不准使用集合对象改变集合中的元素个数, 如果要添加或删除要用迭代器的方法. 2.如果使用类集合对象改变集合中的 ...
- gulp-webpack工程化实现electron
参考网站: https://www.npmjs.com/package/babel-loader https://www.npmjs.com/package/gulp https://www.npmj ...
- Django开发博客 入门篇
Django是神马? Django是一个开源免费的Web框架,使用Python编写.能够让你快速写出一个Web应用, 因为它包含了绝大部分的组件,比如认证,表单,ORM,Session,安全,文件上传 ...
- jmeter 建立一个网络服务的测试计划
如何创建一个 测试计划 测试一个网络服务. 你会 创建5个用户发送请求到一页. 同时,你会告诉用户运行测试两次. 的总数 请求用户请求(5)x(1)x(重复2次)= 10 HTTP请求. 来 建立测试 ...
- [redis] Redis 配置文件置参数详解
################################ 基础配置 ################################# #daemonize no 默认情况下, redis 不 ...
- arcgis API for javascript 学习笔记
ArcGis Server地图是缓存的,意味着它有服务器管理员简历提示性能的一组预先渲染的切片.由于这个原因地图通过ArcGISTiledMapServiceLayer表示 如果地图服务没有一个可用的 ...
- 未能加载文件或程序集“System.Data.SQLite”或它的某一个依赖项。解决办法
找到使用中的程序池,右键,设置应用程序默认设置,如下 确定即可.
- 怎样打造一个分布式数据库——rocksDB, raft, mvcc,本质上是为了解决跨数据中心的复制
摘自:http://www.infoq.com/cn/articles/how-to-build-a-distributed-database?utm_campaign=rightbar_v2& ...