关于窗口和视图

原文地址:https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/Introduction/Introduction.html


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中,你可以使用窗口(windows)和视图(views)来呈现你的程序的内容在屏幕上。窗口(windows)不能直接看到她们但是可以为你的程序的视图提供一个容器。视图就是你想充满容器内容的一部分。例如,你也许有一些视图来展示图片、文字、图形活着一些它们的组合。你当然还可以用视图来管理其他的视图。(注:个人理解就是在视图上加载其他视图的意思)。

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.


每一个程序有至少一个窗口(window)和一个视图(view)来展示它的内容。UIKit和其他的系统框架提供了一些定义好的视图来让你使用展示你的内容。这些视图从简单的按钮和文字到复杂的视图像列表(table view) picker  view和 scroll views(注:这几个还是本来的名字吧,叫法不同)。某些地方这些已经定义好的视图不能满足你的需要,你可以自己定义视图并且管理自己的视图和事件处理。

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.

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. 

Relevant Chapters: View and Window ArchitectureViews

一个视图是UIView类的实例变量(或者是它的子类)管理你程序窗口的一个矩形区域。视图负责绘画的内容,处理触摸的事件,和管理子视图的布局。绘画涉及用使用图形技术像 Core Graphics, OpenGL ES, 或者UIKit来画图形,图片和文字在视图矩形区域内。一个视图响应在它范围内的触摸并且用手势识别或者直接处理触摸事件。在视图层次结构中,父视图是动态负责定位和限制子视图大小的。这个能力来动态修改子视图让你的视图根据条件调整,例如旋转界面和动画。

你可以认为视图是一些建筑用的块,你可以用它们来搭建你的页面。而不是用一个视图来展示你所有的内容。你经常使用不同的视图来搭建一个层的层次结构(注:复杂的视图展示有多个view组合)。每个视图在层次结构中占一个特殊的角色在你的用户界面里并对你的页面进行了特定的优化。例如,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. 

Relevant Chapters: Windows

一个窗口是UIWindow类的实例变量,管理你程序的所有的页面。窗口从事视图(管理的视图控制器)相互作用,转换,展示视图层次结构。大多数时候你的程序窗口不会变。在一个窗口创建后,他保持不变并且只有展示视图的变化。每个程序至少有一个窗口来展示程序的用户页面在设备的主屏幕上。如果一个外部显示链接到设备,程序也会创建第二个窗口来展示在那个屏幕上。


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. 

Relevant Chapters: Animations

动画让给用户提供可见的视图层次更改的反馈。系统定义的标准的动画来展示视图和不同视图之间的转换。然而,视图许多的属性可以直接直接动画。例如通过改变一个视图的透明度来实现,它在屏幕的位置,它的大小,背景颜色或者其他的属性。如果你直接操作视图底层的Core Animation变量,你也可以实现更多的动画。


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.

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. 

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 简称:IB)是一个你可以用图形构建和设置你程序窗口和视图的可视化窗口。使用IB,你组合你的额视图并且把它们放在一个nib文件中,这是一个资源文件,存储视图和其他对象的地方。当你加载一个nib文件在运行时,里面的物体被改组为实际的对象,你的代码就可以编程操作。

IB极大的简化了你要创建的用户页面工作。因为支持界面生成器和nib文件整个iOS界通用,不需要太多精力将nib文件到应用程序的设计。(就是简化了适配,自己理解)

更多关于IB的使用信息,请看Interface Builder User Guide。更多信息冠以怎么管理视图控制器和nib中视图的,看创建自动移的视图控制器在 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.


因为视图这么灵活多变和复杂,所以不可能涵盖所有的内容在一个文件。然而,其他文档可帮助您了解管理视图和用户界面的其他方面的问题。

视图控制器是管理应用程序的视图的一个重要部分。一个视图控制器主持管理它所有的视图在屏幕上有利于视图的呈现。有关视图控制器的更多信息以及它们的作用,请看 View Controller Programming Guide for iOS.

视图是您的应用程序中的手势和触摸事件的主要关系人(就是手势事件基本都是作用于view上的)。有关使用手势识别和直接处理触摸事件的更多信息,Event Handling Guide for iOS.

自定义视图必须使用现有的绘图技术来显示其内容。有关在视图中绘制使用这些技术的资料,看 Drawing and Printing Guide for iOS.

在标准视图动画不够用的地方,你可以使用核心动画。有关实现使用核心动画的信息,看Core Animation Programming Guide.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值