View Programming Guide for iOS_读书笔记[正在更新……]
原文:View Programming Guide for iOS
1 Introduction
先熟悉一下基本概念.
Window
- Windows do not have any visible content themselves but provide a basic container for your application’s views.
- Every application has at least one window that displays the application’s user interface on a device’s main screen.
view
- You can also use views to organize and manage other views.
Views Manage Your Application’s Visual Content.
Views are responsible for drawing content, handling multitouch events, and managing the layout of any subviews.
window和view关系
- Views define a portion of a window that you want to fill with some content.
Animation
Animations Provide the User with Visible Feedback for Interface Changes
Interface Builder
- Interface Builder is an application that you use to graphically construct and configure your application’s windows and views.
- When you load a nib file at runtime, the objects inside it are reconstituted into actual objects that your code can then manipulate programmatically.
2 View and Window Architecture
2.1 View Architecture Fundamentals
2.1.1 View Hierarchies and Subview Management
- Views and windows present your application’s user interface and handle the interactions with that interface.
- A view object defines a rectangular region on the screen and handles the drawing and touch events in that region.
- window ——which is also a view.
View 和 Layer 的关系
- To understand the relationship between views and layers。通过下面的图理解view和layer的关系。

通过上图我们可以看出:
Every view in UIKit is backed by a layer object (usually an instance of the CALayer class), which manages the backing store for the view and handles view-related animations.
Every view has a corresponding layer object that can be accessed from that view’s layer property. (Because a bar button item is not a view, you cannot access its layer directly.)
注意:a bar button item ——which is not a view itself but which manages a view internally。
- 在开发时,要尽量少地调用绘制界面的代码。因为 The actual drawing code of a view object is called as little as possible, and when the code is called, the results are cached by Core Animation and reused as much as possible later.
View 和 Subview的关系
- 只要子视图不透明,就能遮盖父视图的事件响应。 If the subview is totally opaque, then the area occupied by the subview completely obscures the corresponding area of the parent.
- Each superview stores its subviews in an ordered array .
- 改变父视图的大小会在子视图中引起连锁反应。Changing the size of a parent view has a ripple effect that can cause the size and position of any subviews to change too.
2.1.2 The View Drawing Cycle
- The
UIViewclass uses an on-demand drawing model for presenting content. When a view first appears on the screen, the system asks it to draw its content. The system captures a snapshot of this content and uses that snapshot as the view’s visual representation.
2.1.3 Content Modes
- Each view has a content mode that controls how the view recycles its content in response to changes in the view’s geometry and whether it recycles its content at all.
Figure 1-2 Content mode comparisons



总结:所谓ContentMode,就是内容的显示方式,通过正确使用ContentMode可以非常方便地填充内容。尤其在使用UIimage的时候,可能就能省掉UIImageView这个过渡环节。直接在UIView中满屏填充。
2.1.4 Stretchable Views
- You can designate a portion of a view as stretchable/ so that /when the size of the view changes /only the content in the stretchable portion is affected.
2.1.5 Built-In Animation Support
- One of the benefits of having a layer object behind every view is that you can animate many view-related changes easily.
frame—Use this to animate position and size changes for the view.bounds—Use this to animate changes to the size of the view.center—Use this to animate the position of the view.transform—Use this to rotate or scale the view.alpha—Use this to change the transparency of the view.backgroundColor—Use this to change the background color of the view.contentStretch—Use this to change how the view’s contents stretch.In addition to the animations you create using UIKit classes, you can also create animations using Core Animation layers. Dropping down to the layer level gives you much more control over the timing and properties of your animations.
Among the properties you can animate on a UIView object are the following:
2.2 View Geometry and Coordinate Systems
- The default coordinate system in UIKit has its origin in the top-left corner and has axes that extend down and to the right from the origin point.
- In addition to the screen coordinate system, windows and views define their own local coordinate systems that allow you to specify coordinates relative to the view or window origin instead of relative to the screen.
2.2.1 The Relationship of the Frame, Bounds, and Center Properties
A view object tracks its size and location using its frame, bounds, and center properties:
The
frameproperty contains the frame rectangle, which specifies the size and location of the view in its superview’s coordinate system.The
boundsproperty contains the bounds rectangle, which specifies the size of the view (and its content origin) in the view’s own local coordinate system.The
centerproperty contains the known center point of the view in the superview’s coordinate system.

- By default, a view’s frame is not clipped to its superview’s frame. Thus, any subviews that lie outside of their superview’s frame are rendered in their entirety. In other words, touch events occurring in a part of a view that lies outside of its superview’s bounds rectangle are not delivered to that view.
2.2.2 Coordinate System Transformations
- Coordinate system transformations offer a way to alter your view (or its contents) quickly and easily. An affine transform is a mathematical matrix that specifies how points in one coordinate system map to points in a different coordinate system.
2.2.3 Points Versus Pixels
- In iOS, all coordinate values and distances are specified using floating-point values in units referred to as points.
- One point does not necessarily correspond to one pixel on the screen.
2.3 The Runtime Interaction Model for Views
2.4 Tips for Using Views Effectively
2.4.1 Views Do Not Always Have a Corresponding View Controller
- There is rarely a one-to-one relationship between individual views and view controllers in your application. The job of a view controller is to manage a view hierarchy, which often consists of more than one view used to implement some self-contained feature.
- As you design your application’s user interface, it is important to consider the role that view controllers will play. View controllers provide a lot of important behaviors, such as coordinating the presentation of views on the screen, coordinating the removal of those views from the screen, releasing memory in response to low-memory warnings, and rotating views in response to interface orientation changes. Circumventing these behaviors could cause your application to behave incorrectly or in unexpected ways.
- Although custom drawing is necessary at times, it is also something you should avoid whenever possible. The only time you should truly do any custom drawing is when the existing system view classes do not provide the appearance or capabilities that you need. Any time your content can be assembled with a combination of existing views, your best bet is to combine those view objects into a custom view hierarchy.
For more information view controllers and their role in applications, see View Controller Programming Guide for iOS.
2.4.2 Minimize Custom Drawing
2.4.3 Take Advantage of Content Modes
2.4.4 Declare Views as Opaque Whenever Possible
UIKit uses the opaque property of each view to determine whether the view can optimize compositing operations. Setting the value of this property to YES for a custom view tells UIKit that it does not need to render any content behind your view. Less rendering can lead to increased performance for your drawing code and is generally encouraged. Of course, if you set the opaque property to YES, your view must fill its bounds rectangle completely with fully opaque content.
2.4.5 Adjust Your View’s Drawing Behavior When Scrolling
Scrolling can incur numerous view updates in a short amount of time. If your view’s drawing code is not tuned appropriately, scrolling performance for your view could be sluggish. Rather than trying to ensure that your view’s content is pristine at all times, consider changing your view’s behavior when a scrolling operation begins. For example, you can reduce the quality of your rendered content temporarily or change the content mode while a scroll is in progress. When scrolling stops, you can then return your view to its previous state and update the contents as needed.
2.4.6 Do Not Customize Controls by Embedding Subviews
Although it is technically possible to add subviews to the standard system controls—objects that inherit from UIControl—you should never customize them in this way. Controls that support customizations do so through explicit and well-documented interfaces in the control class itself. For example, the UIButton class contains methods for setting the title and background images for the button. Using the defined customization points means that your code will always work correctly. Circumventing these methods, by embedding a custom image view or label inside the button, might cause your application to behave incorrectly now or at some point in the future if the button’s implementation changes.
View Programming Guide for iOS_读书笔记[正在更新……]的更多相关文章
- View Programming Guide for iOS_读书笔记
关于Window的定义的要点 Windows do not have any visible content themselves but provide a basic container for ...
- 【IOS笔记】View Programming Guide for iOS -1
原文:View Programming Guide for iOS View and Window Architecture Views and windows present your applic ...
- Collection View Programming Guide for iOS---(七)---Custom Layouts: A Worked Example
Custom Layouts: A Worked Example Creating a custom collection view layout is simple with straightfor ...
- View Programming Guide for iOS ---- iOS 视图编程指南(四)---Views
Views Because view objects are the main way your application interacts with the user, they have many ...
- Collection View Programming Guide for iOS---(一)----About iOS Collection Views
Next About iOS Collection Views 关于iOS Collection Views A collection view is a way to present an orde ...
- Table View Programming Guide for iOS---(四)---Navigating a Data Hierarchy with Table Views
Navigating a Data Hierarchy with Table Views 导航数据表视图层次 A common use of table views—and one to which ...
- Table View Programming Guide for iOS---(一)---About Table Views in iOS Apps
About Table Views in iOS Apps Table views are versatile user interface objects frequently found in i ...
- View Programming Guide for iOS ---- iOS 视图编程指南(五)---Animations
Animations Animations provide fluid visual transitions between different states of your user inter ...
- Collection View Programming Guide for iOS---(三)---Designing Your Data Source and Delegate
Designing Your Data Source and Delegate 设计你的数据源和委托 Every collection view must have a data source o ...
随机推荐
- oracle锁表查询,资源占用,连接会话,低效SQL等性能检查
查询oracle用户名,机器名,锁表对象 select l.session_id sid, s.serial#, l.locked_mode, l.oracle_username, l.os_user ...
- 001_软件waf
一.优秀的软件waf开源软件 <1>openwaf介绍 http://www.oschina.net/p/openwaf http://git.oschina.net/miracleqi ...
- webpack2.0学习
1.进到指定的目录下,新建自己的文件名 mkdir webpack-test 创建你的项目名称或者你己有的项目名称cd webpack-test npm initnpm install webpack ...
- 动态规划(dp)专题
航线设置 问题描述在美丽的莱茵河畔,每边都分布着N个城市,两边的城市都是唯一对应的友好城市,现需要在友好城市间开通航线以加强往来,但因为莱茵河常年大雾,如果开设的航线发生交叉就有可能出现碰船的现象 ...
- MyISAM引擎和InnoDB引擎的特点
随着MySQL的不断更新,由于各存储引擎功能特性差异较大,这篇文章主要是介绍如何来选择合适的存储引擎来应对不同的业务场景,朋友们可以根据业务需求,选择合适的存储引擎.^.^ MyISAM 特性 不支持 ...
- 《深入分析JavaWeb技术内幕》学习笔记
第一章 深入Web请求过程 1.1 B/S网站架构概述 HTTP协议采用无状态的短连接的通信方式.通常一次请求就完成一次数据交互,通常也对应一个业务逻辑. 当在浏览器里输入一个URL,首先会请求DNS ...
- 【struts2基础】配置详解
一.struts2工作原理(网友总结,千遍一律) 1 客户端初始化一个指向Servlet容器(例如Tomcat)的请求2 这个请求经过一系列的过滤器(Filter)(这些过滤器中有一个叫做Action ...
- 关于 win10 创建WiFi热点 问题(无法启动承载网络 , 我们无法设置移动热点,因为你的电脑未建立以太网,wifi或手机网络数据连接 )
电脑创建WiFi,一般三种办法: 1. WiFi共享软件:猎豹wifi.wifi共享精灵.wifi共享大师..... 2. 命令提示符 netsh wlan set hostednetwork mod ...
- Pandas常用命令
一.数据导入和导出 (一)读取csv文件 1.本地读取 import pandas as pd df = pd.read_csv('tips.csv') #根据自己数据文件保存的路径填写(p.s. p ...
- 常见Java库漏洞汇总
1.ActiveMQ 反序列化漏洞(CVE-2015-5254) ref:https://www.nanoxika.com/?p=408 Apache ActiveMQ是美国阿帕奇(Apache)软件 ...