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

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

Introduction

引言

About Windows and Views

一、關(guān)于窗口和視圖

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中,你使用窗口和視圖在屏幕上呈現(xiàn)你的應(yīng)用的內(nèi)容。窗口本身沒有可見的內(nèi)容卻為你的應(yīng)用的視圖提供了一個(gè)基本的容器。視圖定義了窗口中你需要在里面填充一些內(nèi)容的那部分。例如,你可能有顯示圖片、文本、形狀或者是它們的組合的視圖。你也能夠用視圖去組裝和管理其他視圖。

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.

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

Views Manage Your Application’s Visual Content

三、視圖管理你應(yīng)用的可視內(nèi)容

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類(或它的子類)的一個(gè)實(shí)例,它管理著你的應(yīng)用窗口中的一個(gè)矩形區(qū)域。視圖負(fù)責(zé)繪制內(nèi)容,處理多點(diǎn)觸控事件和管理任何subviews的布局。繪圖包含使用圖像技術(shù)如Core Graphics, OpenGL ES,或者UIKit來繪制形狀,圖像和視圖的矩形區(qū)域內(nèi)部的文本。視圖通過使用手勢識別或是直接處理觸摸事件來響應(yīng)在它矩形區(qū)域的觸摸事件。在視圖的層級中,父視圖負(fù)責(zé)對它們的子視圖定位和定尺寸并能夠動態(tài)的進(jìn)行處理。動態(tài)地修改子視圖的能力讓你的視圖能夠適應(yīng)不斷變化的環(huán)境,例如界面旋轉(zhuǎn)和動畫。

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.

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

Relevant Chapters:View

and Window Architecture,Views

Windows Coordinate the Display of Your Views

四、窗口協(xié)調(diào)你的視圖的顯示

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類的實(shí)例,它處理你整個(gè)應(yīng)用的用戶界面的顯示。窗口與視圖(和他們擁有的視圖控制器)協(xié)作管理可見視圖層級的交互和變化。就絕大部分而言,你的應(yīng)用的窗口絕不會改變。當(dāng)window創(chuàng)建以后,它會保持不變僅僅視圖通過它來改變顯示。每個(gè)應(yīng)用至少有一個(gè)窗口用來在設(shè)備的主屏幕上顯示應(yīng)用的用戶界面。假如一個(gè)外部的顯示器連接到這個(gè)設(shè)備,應(yīng)用程序也能夠創(chuàng)建第二個(gè)窗口在那個(gè)屏幕上顯示內(nèi)容。

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.

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

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.

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

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.

界面生成器簡化了你在創(chuàng)建你應(yīng)用的用戶界面的工作。因?yàn)閷缑嫔善骱蚽ib文件的支持被集成到整個(gè)iOS里,在你應(yīng)用的設(shè)計(jì)中集成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.

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

See Also

七、同時(shí)參考

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.

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

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.

視圖控制器是管理你應(yīng)用views的重要部分。一個(gè)視圖控制器管理著一個(gè)視圖層級里的所有視圖,而且方便這些視圖顯示在屏幕上。更多關(guān)于視圖控制器和他們運(yùn)行的規(guī)則的信息,請查看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.

在你的應(yīng)用程序中視圖是手勢和觸摸事件的關(guān)鍵接收者。關(guān)于更多使用手勢識別和直接處理觸摸事件的信息,請查看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.

自定義視圖必須使用有效的繪制技術(shù)用來呈現(xiàn)他們的內(nèi)容。關(guān)于在你的視圖內(nèi)使用這些技術(shù)進(jìn)行繪制的信息,請查看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.

某些地方標(biāo)準(zhǔn)的視圖動畫是不足的,你可以使用Core Animation。關(guān)于使用Core Animation執(zhí)行動畫的信息,請參考Core Animation Programming Guide

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

推薦閱讀更多精彩內(nèi)容