[toc]
Introduction 简介
关于窗口和视图
In iOS, you use windows and views to present your application’s content on the screen. Windows do not have any visible content themselves but provide a basic container for your application’s views. Views define a portion of a window that you want to fill with some content. For example, you might have views that display images, text, shapes, or some combination thereof. You can also use views to organize and manage other views.
在 iOS 中, 你用窗口(windows)和视图(views) 呈现应用在屏幕上的内容. 窗口自身没有任何可见内容, 它们为应用的视图提供基本的容器. 视图定义了窗口的一部分, 在这里你用一些内容来填充. 例如, 你有一些展示图片, 文本, 形状, 或它们的组合的视图. 你可以用视图去管理和组织其他视图.
概览
Every application has at least one window and one view for presenting its content. UIKit and other system frameworks provide predefined views that you can use to present your content. These views range from simple buttons and text labels to more complex views such as table views, picker views, and scroll views. In places where the predefined views do not provide what you need, you can also define custom views and manage the drawing and event handling yourself.
每个应用都至少拥有一个窗口和一个视图来呈现它的内容.
UIKit 和 其它系统框架提供封装好的视图, 你可以用来呈现你的内容.
这些视图的范围从简单的按钮(button)和文本标签(label), 到复杂的表视图(tableView), 选择器视图(pickerView), 和滚动视图(scrollView).
如果系统封装的视图满足不了你的需求, 你可以自定义视图, 自己画界面和处理事件.
视图管理应用程序的可见内容
A view is an instance of the UIView class (or one of its subclasses) and manages a rectangular area in your application window. Views are responsible for drawing content, handling multitouch events, and managing the layout of any subviews. Drawing involves using graphics technologies such as Core Graphics, OpenGL ES, or UIKit to draw shapes, images, and text inside a view’s rectangular area. A view responds to touch events in its rectangular area either by using gesture recognizers or by handling touch events directly. In the view hierarchy, parent views are responsible for positioning and sizing their child views and can do so dynamically. This ability to modify child views dynamically lets your views adjust to changing conditions, such as interface rotations and animations.
一个视图(view)是 UIView 类(或子类)的实例, 它管理应用程序窗口内的一个矩形区域.
视图负责描绘内容, 处理多点触摸事件, 管理子视图的布局.
绘画包含用图形技术, 例如 Core Graphics, OpenGL ES, 或 UIKit, 来画视图矩形区域内形状, 图片和文本;
一个视图响应它矩形区域内的触摸事件, 通过手势识别(gesture recognizers)或直接处理触摸事件(handling touch events).
在视图的层级中, 父视图负责静态或动态布局它们的子视图.
动态改变子视图的能力, 让你的视图适应变化的状态, 例如界面旋转和动画.
You can think of views as building blocks that you use to construct your user interface. Rather than use one view to present all of your content, you often use several views to build a view hierarchy. Each view in the hierarchy presents a particular portion of your user interface and is generally optimized for a specific type of content. For example, UIKit has views specifically for presenting images, text and other types of content.
你可以把视图当做是你构建用户界面的积木.
通常你会用几个视图来构建视图层级, 而不是只用一个视图来呈现所有内容
层级中的每个视图呈现你界面特定的一部分, 而且通常是为特定类型的内容做了优化.
例如, UIKit 有专门用于呈现图片, 文本和其它类型的内容的视图. ,
窗口协调视图的显示
A window is an instance of the UIWindow class and handles the overall presentation of your application’s user interface. Windows work with views (and their owning view controllers) to manage interactions with, and changes to, the visible view hierarchy. For the most part, your application’s window never changes. After the window is created, it stays the same and only the views displayed by it change. Every application has at least one window that displays the application’s user interface on a device’s main screen. If an external display is connected to the device, applications can create a second window to present content on that screen as well.
一个窗口是一个 UIWindow 类的实例, 处理你应用界面的整体呈现.
窗口和视图(和控制器)一起管理交互和更改可见的视图层级.
多半情况下,你应用程序的窗口不会改变.
在窗口创建之后, 它保持不变, 只有现实的视图改变.
每个应用都有至少一个窗口, 来显示设备屏幕上的应用程序界面.
如果连接一个外部显示器到设备上, 应用程序可以创建一个第二窗口来呈现内容到那个屏幕上.
动画为用户提供可见的界面变化反馈
Animations provide users with visible feedback about changes to your view hierarchy. The system defines standard animations for presenting modal views and transitioning between different groups of views. However, many attributes of a view can also be animated directly. For example, through animation you can change the transparency of a view, its position on the screen, its size, its background color, or other attributes. And if you work directly with the view’s underlying Core Animation layer object, you can perform many other animations as well.
动画为用户提供关于视图层级的变化的可见反馈.
系统为模态呈现视图(modal)和不同视图之间的转场(transitioning)
定义了标准动画.
尽管如此, 视图的大多数属性也是可以直接动画的.
例如, 通过动画你可以改变视图的透明度, 在屏幕上的位置, 它的大小, 背景色, 或其它属性.
如果直接操作视图的底层核心动画层(Core Animation layer)对象, 你可以执行许多其它动画.
IB 的规则
Interface Builder is an application that you use to graphically construct and configure your application’s windows and views. Using Interface Builder, you assemble your views and place them in a nib file, which is a resource file that stores a freeze-dried version of your views and other objects. When you load a nib file at runtime, the objects inside it are reconstituted into actual objects that your code can then manipulate programmatically.
界面生成器(Interface Builder), 是一个你用来 图形化构建,配置你应用窗口和视图 的程序.
在用界面生成器是, 你把你的视图放在一个 nib 文件中, 它是一个资源文件存储你的视图和其它对象的冻干(freeze-dried?)版本.
当你在运行时加载了一个 nib 文件, 它里面的物体被改组为实际的对象, 来让你用代码编程操作.
Interface Builder greatly simplifies the work you have to do in creating your application’s user interface. Because support for Interface Builder and nib files is incorporated throughout iOS, little effort is required to incorporate nib files into your application’s design.
界面生成器极大的简化了你创建应用界面时的工作.
因为支持界面生成器和 nib 文件是纳入整个 iOS 的, 花费一点小努力把 nib 文件纳入到你的程序设计中是值得的.