The Core Objects of Your App

Core App Objects
App核心对象


UIKit provides the infrastructure for all apps but it is your custom objects that define the specific behavior of your app. Your app consists of a handful of specific UIKit objects that manage the event loop and the primary interactions with iOS. Through a combination of subclassing, delegation, and other techniques, you modify the default behaviors defined by UIKit to implement your app.
UIKit为所有的apps提供了基础设施,也可以为你的app定义具体行为的定制对象。你的app由少数具体的管理事件循环和与iOS交互的UIKit具体的对象组成。通过组合子类,委托和其他的技术,你可以修改UIKit定义的默认行为来实现你的app。


In addition to customizing the UIKit objects, you are also responsible for providing or defining other key sets of objects. The largest set of objects is your app’s data objects, the definition of which is entirely your responsibility. You must also provide a set of user interface objects, but fortunately UIKit provides numerous classes to make defining your interface easy. In addition to code, you must also provide the resources and data files you need to deliver a shippable app.
为了定制UIKit对象,你也有责任提供或者定义其它的对象的关键集合,最大的对象集合是你的app的数据对象,定义数据对象整个都是你的任务。你也必须提供一个用户界面对象集合,幸运的是UIKit提供了许多类来让你定义界面更简单。除了代码,你必须提供资源和数据文件,如果你想要在商店发布你的app。


The Core Objects of Your App
你的App的核心对象


From the time your app is launched by the user, to the time it exits, the UIKit framework manages much of the app’s core behavior. At the heart of the app is the UIApplication object, which receives events from the system and dispatches them to your custom code for handling. Other UIKit classes play a part in managing your app’s behavior too, and all of these classes have similar ways of calling your custom code to handle the details.
一旦你的app被用户运行,直到退出,UIKit框架管理app的核心动作。zpp的心脏是UIApplication对象,它从系统接受事件,分发到处理事件的用户代码。其他的UIKit类也在管理app的行为上扮演一定的角色,所有的这些类都有相同的方式来调用你的用户代码来处理细节。


To understand how UIKit objects work with your custom code, it helps to understand a little about the objects make up an iOS app. Figure 2-1 shows the objects that are most commonly found in an iOS app, and Table 2-1 describes the roles of each object. As you can see from the diagram, iOS apps are organized around the model-view-controller design pattern. This pattern separates the data objects in the model from the views used to present that data. This separation promotes code reuse by making it possible to swap out your views as needed and is especially useful when creating universal apps—that is, apps that can run on both iPad and iPhone.
为了理解UIKit对象如何与你的用户代码工作,它有助于理解一些对象组织起一个iOS app. 下图显示了在一个iOS app中经常出现的对象,下面的表描述了每个对象的角色。正如你可以从图表中看到的,iOS apps由MVC组织。这个模式从view中分离了数据对象。这个分离促进了代码复用,通过使他在view中被交换出,当创建一个通用的app的时候很有用,让app可以运行在iPad和iPhone上。


图2-1
        Model
Data Objects<---->Document<------------
                     ^                 |
                     |                 |
                     V                 |
        Controller                     |                     View
UIApplication---->Application Delegate-|------------>      UIWindow
       |                |              |                        |
       |                |              |                        |
       V                V          <---|                            V
 Event Loop         View Controller<---------------->Views and UI Object
 
 用户对象:Application Delegate
 系统对象:UIApplication UIWindow
 既是系统又是用户对象:Data Objects, Document, View Controller, Views and UI Objects.
 
 表2-1 在一个iOS app中的对象的角色
 UIApplication object: 
 You use the UIApplication object essentially as is—that is, without subclassing. This controller object manages the app event loop and coordinates other high-level app behaviors. Your own custom app-level logic resides in your app delegate object, which works in tandem with this object.
 使用的UIApplication对象是没有子类的。这个控制对象管理着app事件循环和协调其他的高层app行为。你自己的用户应用层逻辑驻留在你的app委托对象,委托对象与本对象以串联的方式工作。
 App delegate object:
 The app delegate is a custom object created at app launch time, usually by the UIApplicationMain function. The primary job of this object is to handle state transitions within the app. For example, this object is responsible for launch-time initialization and handling transitions to and from the background. For information about how you use the app delegate to manage state transitions, see “Managing App State Changes.”
In iOS 5 and later, you can use the app delegate to handle other app-related events. The Xcode project templates declare the app delegate as a subclass of UIResponder. If the UIApplication object does not handle an event, it dispatches the event to your app delegate for processing. For more information about the types of events you can handle, see UIResponder Class Reference.
应用程序委托是一个用户对象,在应用程序启动的时候建立。通常由UIApplicationMain函数。这个对象的主要工作是处理app的状态转换。举例,这个对象在启动时负责初始化和处理转换到或者转换出后台。关于如何使用应用程序委托的信息参考"Managing App State Changes"
在iOS 5或者更新的系统中,你可以使用app delegate来处理其他的应用程序有关事件。Xcode工程模板把app delegate声明为一个UIResponder的子类。如果UIApplication对象没有处理某个事件,它把这个事件分发到你的应用程序委托来处理。关于你可以处理的事件类型参考"UIResponder Class Reference"
Documents and data model objects:
Data model objects store your app’s content and are specific to your app. For example, a banking app might store a database containing financial transactions, whereas a painting app might store an image object or even the sequence of drawing commands that led to the creation of that image. (In the latter case, an image object is still a data object because it is just a container for the image data.)
Apps can also use document objects (custom subclasses of UIDocument) to manage some or all of their data model objects. Document objects are not required but offer a convenient way to group data that belongs in a single file or file package. For more information about documents, see “Defining a Document-Based Data Model.”
数据模型对象存储你的应用程序的内容和具体的你的程序。举例,一个银行的app可能存储了一个包含了金融交易的数据库。一个绘画的app可能存储了一个图形对象或者一系列绘画命令。(在绘画例子中,一个图形对象仍然是一个数据对象因为它是一个图形数据的容器)
apps也能够使用文档对象(UIDocument的用户子类)来管理一些或者全部数据模型。文档对象不是必须的,但是它提供了一个方便的方法来组织在一个单独文件或者文件包中的对象。关于文档的信息参考"Defining a Document-Based Data Model"
View controller objects
View controller objects manage the presentation of your app’s content on screen. A view controller manages a single view and its collection of subviews. When presented, the view controller makes its views visible by installing them in the app’s window.
The UIViewController class is the base class for all view controller objects. It provides default functionality for loading views, presenting them, rotating them in response to device rotations, and several other standard system behaviors. UIKit and other frameworks define additional view controller classes to implement standard system interfaces such as the image picker, tab bar interface, and navigation interface.
For detailed information about how to use view controllers, see View Controller Programming Guide for iOS.
视图控制模型管理你的应用程序在屏幕上的表现。一个视图控制器管理一个单独的视图和它的子视图。当显示的时候,视图控制器通过将它的views安装到应用程序窗口来让它们可见。
UIViewController类是所有视图控制器对象的基类。它提供了默认的功能来装载视图,显示它们,旋转它们在设备旋转的时候。以及一些其他的标准系统行为。UIKit和其他的框架定义了另外的视图控制器类来实现标准的系统界面,比如图像选择器,tab栏界面和导航界面。
关于如何使用视图控制器的更多信息请参考"View Controller Pogramming Guide for iOS"
UIWindow object
A UIWindow object coordinates the presentation of one or more views on a screen. Most apps have only one window, which presents content on the main screen, but apps may have an additional window for content displayed on an external display.
To change the content of your app, you use a view controller to change the views displayed in the corresponding window. You never replace the window itself.
In addition to hosting views, windows work with the UIApplication object to deliver events to your views and view controllers.
UIWindow对象协调一个屏幕上的一个或多个视图的显示。大多数应用程序只有一个窗口,在主屏幕上显示内容,但是apps可以有另外一个窗口在一个扩展窗口上显示窗口。
为了应用程序的内容。使用一个视图控制器来改变在相关窗口上的视图显示。你不需要替换窗口本身。
对于主视图,窗口由UIApplication对象来分发时间到你的视图和视图控制器。
View control and layer objects
Views and controls provide the visual representation of your app’s content. A view is an object that draws content in a designated rectangular area and responds to events within that area. Controls are a specialized type of view responsible for implementing familiar interface objects such as buttons, text fields, and toggle switches.
The UIKit framework provides standard views for presenting many different types of content. You can also define your own custom views by subclassing UIView (or its descendants) directly.
In addition to incorporating views and controls, apps can also incorporate Core Animation layers into their view and control hierarchies. Layer objects are actually data objects that represent visual content. Views use layer objects intensively behind the scenes to render their content. You can also add custom layer objects to your interface to implement complex animations and other types of sophisticated visual effects.
视图和控制提供了应用程序内容的可视化表现。一个视图是一个对象,这个对象把内容画在一个矩形区域,并且在这个区域响应事件。控制是视图负责实现相似接口对象的具体类型,比如按钮,文本域和开关。
UIKit框架为显示不同类型的内容提供了标准视图。你也可以自己定义,通过子类UIView。
除了加入视图和控制,apps也能加入核心动画层到它们的视图和控制层次结构中。层对象是实际的数据对象,表现可视的内容。视图使用层对象在场景背后来渲染内容。你也可以添加用户层对象到你的界面来实现复杂的动画和其他类型的复杂的可视效果。


What distinguishes one iOS app from another is the data it manages (and the corresponding business logic) and how it presents that data to the user. Most interactions with UIKit objects do not define your app but help you to refine its behavior. For example, the methods of your app delegate let you know when the app is changing states so that your custom code can respond appropriately.
与其他的应用程序区分开来的是数据,它管理(和相关的业务逻辑)和它如何把数据表现给用户。大多数与UIKit的交互没有定义你的app,但是帮助你提炼它的行为。举例,app委托的方法让你知道了何时app在改变状态,因此你的用户代码能够适当的响应。


For information about the specific behaviors of a given class, see the corresponding class reference. For more information about how events flow in your app and information about your app’s responsibilities at various points during that flow, see “App States and Multitasking.”
关于所给类的具体行为,参考相关类的参考。对于应用程序中的事件流和应用程序的责任在事件流中的多个重点,参考"App States and Multitasking"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值