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 ...
随机推荐
- jsp 颜色和表格控制
表格控制: table{table-layout:fixed; word-wrap:break-word; word-break:break-all;} 颜色列表:
- js中String.prototype.format類似于.net中的string.formitz效果
String.prototype.format = function(args) { if (arguments.length>0) { var result = this; if (argum ...
- python中列表的操作
list1 = ['A' , 'B' , 'C'] list1[0] ; list1[-1] # 取第一个和最后一个元素 list1[ : ] ; list1[ : len(list1)] # 取所有 ...
- SpringMVC整合Quartz实现定时任务以及Tomcat服务执行初始化定时任务
1.导入quartz.jar包,或者pom.xml 配置对应的依赖: <dependency> <groupId>org.quartz-scheduler</groupI ...
- json2.js 使用
参考:http://www.cnblogs.com/youring2/archive/2013/03/01/2938850.html github地址:https://github.com/dougl ...
- struts2视频学习笔记 07-08(为Action的属性注入值,指定需要Struts 2处理的请求后缀,常用常量)
课时7 为Action的属性注入值(增加灵活性,适用于经常更改的参数) Struts2为Action中的属性提供了依赖注入功能,在struts2的配置文件中,我们可以很方便地为Action中的属性注入 ...
- 第三章 XHTML 表单
1.表单的主要作用在于在网页上提供一个图形用户界面,以采集和提交用户输入的数据. 2.HTML表单元素和属性可以分为两种类型:定义表单整体结构,使浏览器知道如何处理表单数据的元素:创建输入控件的元素. ...
- 各种主流数据库的比较(所以说我觉得Oracle这个keng?入的不错?)
随着计算机技术不断发展,各种数据库编程工具也随着发展,使当今的大多数程序开发人员可以摆脱枯燥无味的用计算机指令或汇编语言开发软件,而是利用一系列高效的.具有良好可视化的编程工具去开发各种数据库软件,从 ...
- bzoj 1965: [Ahoi2005]SHUFFLE 洗牌
#include<cstdio> #include<cstring> #include<iostream> #define ll long long using n ...
- hihocoder 1138 Islands Travel dijkstra+heap 难度:2
http://hihocoder.com/problemset/problem/1138 很久不用最短路,几乎连基本性质也忘了,结果这道题就是某些最短路算法空间复杂度是o(n) 这里总结四种算法 算法 ...