2. iOS App 剖析(iOS App Anatomy)
Almost all iOS apps use at least some of the UI components defined by the UIKit framework. Knowing the names, roles, and capabilities of these basic components helps you make informed decisions as you design the UI of your app.
幾乎所有的 iOS app 至少會(huì)使用部分由 UIKit 框架所定義的 UI 組件。了解這些基礎(chǔ)組件的名稱、角色、作用,有助于在設(shè)計(jì) app UI 時(shí)做出更有依據(jù)的決定。
The UI elements provided by UIKit fall into four broad categories:
Bars.?Bars contain contextual information that tell users where they are and controls that help users navigate or initiate actions.
Content views.?Content views contain app-specific content and can enable behaviors such as scrolling, insertion, deletion, and rearrangement of items.
Controls.?Controls perform actions or display information.
Temporary views.?Temporary views appear briefly to give users important information or additional choices and functionality.
UIKit 提供的 UI 元素可以分為四個(gè)大類:
欄(Bar):欄包含上下文相關(guān)的信息,能夠告訴用戶他們處于何處。欄還包含控件,可以幫助用戶導(dǎo)航或發(fā)起操作。
內(nèi)容視圖(Content view):內(nèi)容視圖包含應(yīng)用相關(guān)的內(nèi)容,并且能引發(fā)操作,例如滾動(dòng)、插入、刪除或者條目重排。
控件(Control):控件執(zhí)行操作或者顯示信息。
臨時(shí)視圖(Temporary view):臨時(shí)視圖短暫地出現(xiàn),用來(lái)告知用戶重要的信息或者額外的選擇和功能。
In addition to defining UI elements, UIKit defines objects that implement functionality, such as gesture recognition, drawing, accessibility, and printing support.
Programmatically, a UI element is a type of?view?because it inherits from UIView. A view knows how to draw itself onscreen, and it knows when a user touches within its bounds. Controls (such as buttons and sliders), content views (such as collection views and table views), and temporary views (such as alerts and action sheets) are all types of views.
除了定義 UI 元素,UIKit 還定義了用來(lái)實(shí)現(xiàn)功能的對(duì)象,例如手勢(shì)識(shí)別,繪制,可訪問(wèn)性,打印支持。
從程序的角度來(lái)講,一個(gè) UI 元素是一種類型的視圖(view),因?yàn)樗^承自 UIView。一個(gè)視圖知道如何在屏幕上自我繪制,也能對(duì)用戶在其界線內(nèi)的觸摸有所感知。控件(例如按鈕和滑塊)、內(nèi)容視圖(例如集合視圖和表格視圖)、臨時(shí)視圖(例如警告提示和動(dòng)作表單)都是不同類型的視圖。
To manage a set or hierarchy of views in your app, you typically use a?view controller. A view controller coordinates the display of views, implements the functionality behind user interactions, and can manage transitions from one screen to another. For example, Settings uses a navigation controller to display its hierarchy of views.
Here’s an example of how views and view controllers can combine to present the UI of an iOS app.
為了管理 app 中的一系列視圖,通常需要使用視圖控制器(view controller)。視圖控制器會(huì)協(xié)調(diào)視圖的顯示,實(shí)現(xiàn)用戶交互背后的功能,還能管理屏幕間的切換。例如,設(shè)置(Settings)使用導(dǎo)航控制器來(lái)顯示它的不同層次的視圖。
下面是一個(gè)示例,介紹了視圖與視圖控制器是如何組合在一起來(lái)展示 iOS app 的 UI。
Although developers think in terms of views and view controllers, users tend to experience an iOS app as a collection of screens. From this perspective, a screen generally corresponds to a distinct visual state or mode in an app.
雖然開發(fā)者是從視圖和視圖控制器的角度來(lái)思考,但用戶傾向于把 iOS app 當(dāng)做一組屏幕(screen)來(lái)體驗(yàn)。從這個(gè)角度看,一個(gè)屏幕通常對(duì)應(yīng)于 app 中一個(gè)明顯區(qū)別于其他的可見(jiàn)狀態(tài)或模式。
NOTE
An iOS app includes a window. But—unlike a window in a computer app—an iOS window has no visible parts and it can’t be moved to another location on the display. Most iOS apps contain only one window; apps that support an external display can have more than one.
注:一個(gè) iOS app 包括一個(gè)窗口(window)。但是,不同于電腦軟件中的窗口,一個(gè) iOS 窗口沒(méi)有可見(jiàn)的部分,它也不能在顯示時(shí)被移動(dòng)到另一個(gè)位置。大部分 iOS app 只包含一個(gè)窗口,支持額外顯示的 app 才會(huì)有不止一個(gè)窗口。
In?iOS Human Interface Guidelines, the word?screen?is used as it’s understood by most users. As a developer, you might also read about screens in other contexts, where the term refers to the?UIScreen?object you can use to access an external display screen.
在 iOS 人機(jī)交互指南里使用屏幕(screen)這個(gè)詞是因?yàn)樗鼙淮蠖鄶?shù)用戶所理解。作為一個(gè)開發(fā)者,你可能也會(huì)在其他上下文中讀到關(guān)于屏幕(screen)的內(nèi)容,而那時(shí),這個(gè)詞實(shí)際指的是 UIScreen 對(duì)象,開發(fā)者可以使用該對(duì)象來(lái)訪問(wèn)額外的顯示屏。