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 框架有分别用来代表图像,文本以及其它类型内容的视图。

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 类的一个实例,它处理整个应用程序用户界面的外观。窗口跟视图(以及它们拥有的视图控制器)一起工作,来管理可见视图层次的交互及转换。大多数情况下,应用程序的窗口永远不会改变。 当窗口被创建了之后,它就一直保持不变,只有视图会根据变化显示不同的视图。 任何应用程序都至少有一个窗口,它在设备的主屏幕上显示应用程序的用户界面。 如果有外部显示被连接到设备,应用程序也能在屏幕上创建第二个窗口来呈现内容。

相关章节: “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)层对象工作,你还可以执行很多其它动画。

相关章节: “Animations”

 

The Role of 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.

界面生成器是用来图形化构造和配置应用程序窗口和视图的应用。 使用界面生成器,你组合各种视图,并把它们放在一个nib文件中。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.

界面生成器大大简化了创建应用程序用户界面时你不得不做的工作。 因为整个iOS都支持界面生成器和nib文件,你只需要一点努力就可以把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 “Custom View Controllers” in View Controller Programming Guide for iOS.

要想了解更多有关使用界面生成器的信息,查看《Interface Builder User Guide--界面生成器使用指南》。有关视图控制器如何管理包含各种视图的nib文件的详细信息,查看“Custom 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.

    视图控制器是管理应用程序视图的重要一部分。 一个视图控制器管理着一个视图层次里的所有视图,并让这些视图的外观显示在屏幕上。 关于更多视图控制器的信息以及它们所扮演的角色,请查看 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.

    视图是应用程序中手势和触摸事件的主要接收者。更多关于使用手势辨认器和直接处理触摸事件的信息,请看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.

    自定义视图必须使用可行的绘制技术,用来呈现它们的内容。 关于用来在视图里绘制的这些技术,请看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.

    当标准视图动画没有效果时,你可以使用内核动画。 关于用内核动画实现动画的信息,请看 Core Animation Programming Guide.

 

posted on 2013-06-27 14:48  cainiaozhang  阅读(2279)  评论(0编辑  收藏  举报