iOS学习笔记(6)——翻译苹果文档About Windows and Views

About Windows and Views

关于窗口和视图

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中,你用窗口和视图来在屏幕上呈现你应用内容。窗口本身并不拥有任何可见的内容,而是为你的应用视图提供了基本的容器。视图定义了你想要填充某些内容到窗口中的一部分。例如,你很可能拥有能够显示图片、文字、形状活着某些组合的视图。你同样可以使用视图去组织和管理其他视图。

At a Glance

一瞥

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和其他的系统框架提供预定义的视图,你可以利用它们显示你的内容。这些视图囊括了从简单的按钮、文本标签到复杂的表视图、选择器视图以及滚动视图。在某些场合中,这些与定义的视图不能够满足你的需要,你还可以自定义视图,并且自己管理那些绘图和事件。

Views Manage Your Application’s Visual Content

视图管理你应用的可视内容

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.

一个视图是一个UIView类(或者一个它子类)的实例,并且管理一块在你应用窗口中的矩形区域。视图负责绘图内容、操控多点触控事件以及管理任何子视图的层。绘图使用了图形技术,诸如 Core Graphics, OpenGL ES, 或者 UIKit等,用来在一个视图的矩形区域内绘制图形、图像以及文本。一个视图在它的矩形区域中,通过使用手势识别或直接操作触控事件来响应触碰事件。在视图的等级层次中,父视图负责它们子视图的定位和尺寸,并且可以动态地这样做。这个能力动态地修改你的子视图,让你的视图在诸如界面旋转和动画过渡的变化条件下自适应。

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 拥有专门为显示图像、文本以及其它类型内容的视图。

Relevant Chapters: View and Window ArchitectureViews

Windows Coordinate the Display of Your Views

窗口协调你视图的显示

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类的实例,并且管理你应用用户界面的整体外观。窗口与视图(以及视图自己所属的视图控制器)一同工作,以用来管理与可见视图层的交互以及改变。最重要的一点,你应用的窗口永远不会改变。在窗口被创建之后,它始终保持相同,并且只有视图通过改变来显示。每一个应用至少拥有一个窗口,用来在设备的主屏幕上显示应用的用户界面。如果一个额外的显示界面被连接到设备,应用能够创建第二个窗口来在同一个屏幕上呈现内容。

Relevant Chapters: Windows

Animations Provide the User with Visible Feedback for Interface Changes

动画为用户对界面改变提供可视化的反馈

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. 

动画对你视图层的改变,为用户提供可视化的反馈。系统为呈现模型视图以及在不同视图组织间变化定义标准动画。然而,很多视图的属性同样能直接靠动画改变。例如,通过动画你能够改变视图它的的透明度、它在屏幕上的位置、它的大小、他的背景颜色,或者其他属性。并且,如果你直接用视图潜在的Core Animation 层对象,你同样能够展示很多其他动画。

Relevant Chapters: Animations

The Role of Interface Builder

Interface Builder的作用

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是一个你用来图形化创建以及配置你应用的窗口和视图的应用。使用Interface Builder,你组合你的视图并且将它们放置在一个nib文件中,nib文件是一种储存了一个你视图和其他对象的不变版本的资源文件。当你在运行时加载一个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. 

Interface Builder极大地简化了你在创建你应用的用户界面时不得不做的工作。由于对Interface Builder 和 nib文件的支持合并到iOS中,只需要花费很少的努力就能讲nib文件合并到你应用的设计中去。

For more information about how to use Interface Builder, see Interface Builder User Guide. For information about how view controllers manage the nib files containing their views, see Creating Custom Content View Controllers in View Controller Programming Guide for iOS

对于更多关于如何使用Interface Builder的信息,参见Interface Builder User Guide。对于视图控制器如何管理nib文件来容纳它们的视图,参见Creating Custom Content View Controllers in View Controller Programming Guide for iOS

See Also

同样参见

Because views are very sophisticated and flexible objects, it would be impossible to cover all of their behaviors in one document. However, other documents are available to help you learn about other aspects of managing views and your user interface as a whole.

  • View controllers are an important part of managing your application’s views. A view controller presides over all of the views in a single view hierarchy and facilitates the presentation of those views on the screen. For more information about view controllers and the role they play, see View Controller Programming Guide for iOS.

  • Views are the key recipients of gesture and touch events in your application. For more information about using gesture recognizers and handling touch events directly, see Event Handling Guide for iOS.

  • Custom views must use the available drawing technologies to render their content. For information about using these technologies to draw within your views, see Drawing and Printing Guide for iOS.

  • In places where the standard view animations are not sufficient, you can use Core Animation. For information about implementing animations using Core Animation, see Core Animation Programming Guide

原文地址:https://www.cnblogs.com/nycoder/p/4358811.html