View Programming Guide for iOS——官方文檔翻譯(1)Introduction

初學iOS,翻的不好還請幫忙指正,歡迎大家一起討論學習!

Introduction

引言

About Windows and Views

一、關于窗口和視圖

IniOS, you use windows and views to present your application’s content on thescreen. Windows do not have any visible content themselves but provide a basic containerfor your application’s views.Views definea portion ofawindow that you want to fill with some content.For example, you mighthave views that display images, text, shapes, or some combination thereof. Youcan 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 notprovide what you need, you can also define custom views and manage the drawingand event handling yourself.

每個應用至少有一個窗口和一個視圖用來呈現它的內容。UIKit和其他系統框架提供給你能夠用來呈現你內容的預定義視圖。這些視圖包含從單個按鈕和文本標簽到更復雜的視圖,如table viewspicker views和scroll views。在某些地方預定義視圖無法提供你想要的,你自己也能夠自定義視圖,管理繪圖和事件處理。

Views Manage Your Application’s Visual Content

三、視圖管理你應用的可視內容

A view is an instance of theUIView class (or one of its subclasses) and manages arectangular area in your application window. Views are responsible for drawingcontent, handling multitouch events, and managing the layout of any subviews.Drawing involves using graphicstechnologies such as Core Graphics, OpenGL ES, or UIKit to draw shapes,images, and text inside a view’s rectangular area. A view responds to touchevents in its rectangular area either by using gesture recognizers or byhandling touch events directly. In the view hierarchy,parent views are responsible for positioning and sizing their child viewsand 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類(或它的子類)的一個實例,它管理著你的應用窗口中的一個矩形區域。視圖負責繪制內容,處理多點觸控事件和管理任何subviews的布局。繪圖包含使用圖像技術如Core Graphics, OpenGL ES,或者UIKit來繪制形狀,圖像和視圖的矩形區域內部的文本。視圖通過使用手勢識別或是直接處理觸摸事件來響應在它矩形區域的觸摸事件。在視圖的層級中,父視圖負責對它們的子視圖定位和定尺寸并能夠動態的進行處理。動態地修改子視圖的能力讓你的視圖能夠適應不斷變化的環境,例如界面旋轉和動畫。

Youcan think of views as building blocks that you use to construct your userinterface. Rather than use one view to present all of your content, you oftenuse several views to build a view hierarchy. Each view in the hierarchypresents a particular portion of your user interfaceand is generally optimized for a specific type of content. For example,UIKit has views specifically for presenting images, text and other types ofcontent.

你可以把視圖想象為構建塊,你使用它來組成你的用戶界面。你常常會使用多個視圖來構建一個視圖層級,而不是使用一個視圖來呈現你所有的內容。在層級中的每個視圖呈現了你的用戶界面的某一部分,而且對于特定類型的內容通常是最優的。例如,UIKit有特定地為呈現圖像,文本和其他類型內容的視圖。

Relevant Chapters:View

and Window Architecture,Views

Windows Coordinate the Display of Your Views

四、窗口協調你的視圖的顯示

Awindow is an instance of the UIWindow class and handles the overallpresentation of your application’s user interface. Windows work with views (andtheir owning view controllers) to manage interactions with, and changes to, thevisible view hierarchy. For the most part, your application’s window neverchanges. After the window is created, it stays the same andonly the views displayedby it change.Every application has at least one window that displays the application’s userinterface on a device’s main screen. If an external display is connected to thedevice, applications can create a second window to present content on thatscreen as well.

窗口是UIWindow類的實例,它處理你整個應用的用戶界面的顯示。窗口與視圖(和他們擁有的視圖控制器)協作管理可見視圖層級的交互和變化。就絕大部分而言,你的應用的窗口絕不會改變。當window創建以后,它會保持不變僅僅視圖通過它來改變顯示。每個應用至少有一個窗口用來在設備的主屏幕上顯示應用的用戶界面。假如一個外部的顯示器連接到這個設備,應用程序也能夠創建第二個窗口在那個屏幕上顯示內容。

Relevant Chapters:Windows

Animations Provide the User with Visible Feedback forInterface Changes

五、動畫為界面的變化提供給用戶可視的反饋

Animationsprovide users with visible feedback about changes to your view hierarchy. Thesystem defines standard animations for presenting modal views and transitioningbetween different groups of views. However, many attributes of a view can alsobe animated directly. For example, through animation you can change thetransparency of a view, its position on the screen, its size, its backgroundcolor, or other attributes. And if you work directly with the view’s underlyingCore Animation layer object, you can perform many other animations as well.

對于你視圖層級的改變,動畫提供給用戶可視的反饋。系統定義了標準動畫來呈現模型視圖(modal views)和不同組視圖之間的過渡顯示。然而,視圖的許多屬性也能直接動畫顯示。例如,通過動畫你能夠改變視圖的透明度,在屏幕的位置,尺寸,背景顏色或其他屬性。而且如果你直接地使視圖的底層(underlying)Core Animation layer對象工作,你也能執行許多其他的動畫。

Relevant Chapters:Animations

The Role of Interface Builder

六、界面生成器的作用

InterfaceBuilder is an application that you use to graphically construct and configureyour application’s windows and views. Using Interface Builder, you assembleyour views and place them in a nib file, which is a resource file that stores afreeze-dried version of your views and other objects. When you load a nib fileat runtime, the objects inside it are reconstituted into actual objects thatyour code can thenmanipulate programmatically.

界面生成器是一個應用程序,你使用它來圖形化地構造和配置你應用的窗口和視圖。使用界面生成器,你組合你的views然后把它們放置在一個nib文件里,nib文件是一個存儲你視圖的一個凍干(freeze-dried)版本以及其他對象的資源文件。當你在運行時加載一個nib文件,在它里面的對象被重新生成為你的代碼能夠操作編程的實際對象。

InterfaceBuilder greatly simplifies the work you have to do in creating yourapplication’s user interface. Because support for Interface Builder and nib filesis incorporated throughout iOS, little effort is required to incorporate nibfiles into your application’s design.

界面生成器簡化了你在創建你應用的用戶界面的工作。因為對界面生成器和nib文件的支持被集成到整個iOS里,在你應用的設計中集成nib文件僅需要很少的工作

Formore information about how to use Interface Builder, see Interface Builder UserGuide. For information about how view controllers manage the nib filescontaining their views, see “Creating Custom Content View Controllers” inView Controller Programming Guide for iOS.

為了解更多關于怎樣使用界面生成器的信息,請查看Interface Builder User Guide。有關視圖控制器怎樣管理nib文件和他們的視圖,在View Controller Programming Guide for iOS中查看“Creating Custom Content View Controllers”

See Also

七、同時參考

Becauseviews are very sophisticated and flexible objects, it would be impossible tocover all of their behaviors in one document. However, other documents areavailable to help you learn about other aspects of managing views and your userinterface as a whole.

因為視圖是非常復雜和靈活的對象,不可能在一個文檔中覆蓋它的所有特性。然而,其他文檔作為一個整體可以幫助您了解管理視圖和用戶界面的其他方面。

lView controllers are an important part of managing yourapplication’s views. A view controller presides over all of the views in asingle view hierarchy and facilitates the presentation of those views on thescreen. For more information about view controllers and the role they play, seeView Controller Programming Guide for iOS.

視圖控制器是管理你應用views的重要部分。一個視圖控制器管理著一個視圖層級里的所有視圖,而且方便這些視圖顯示在屏幕上。更多關于視圖控制器和他們運行的規則的信息,請查看View Controller Programming Guide for iOS.

lViews are the key recipients of gesture and touch events in yourapplication. For more information about using gesture recognizers and handlingtouch events directly, seeEvent Handling Guide for iOS.

在你的應用程序中視圖是手勢和觸摸事件的關鍵接收者。關于更多使用手勢識別和直接處理觸摸事件的信息,請查看Event Handling Guide for iOS.

lCustom views must use the available drawing technologies to rendertheir content. For information about using these technologies to draw withinyour views, seeDrawing and Printing Guide for iOS.

自定義視圖必須使用有效的繪制技術用來呈現他們的內容。關于在你的視圖內使用這些技術進行繪制的信息,請查看Drawing and Printing Guide for iOS

lIn places where the standard view animations are not sufficient, you

can use Core Animation. For information about implementing animations using

Core Animation, seeCore Animation Programming Guide.

某些地方標準的視圖動畫是不足的,你可以使用Core Animation。關于使用Core Animation執行動畫的信息,請參考Core Animation Programming Guide

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容