视图和视图控制器 [英] view and viewcontroller

查看:236
本文介绍了视图和视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的iphone应用程序开发者。我想知道view和viewcontroller之间的区别是什么。

I am a new iphone app developer.I want to know what is the difference between view and viewcontroller.

推荐答案

strong> UIView

UIView


UIView类定义了屏幕上的矩形
区域和用于管理该区域内容的接口

在运行时,视图对象处理其区域
中任何内容的
呈现,并处理与
的内容的任何交互。 UIView类本身
提供了基本行为来填充
它的矩形区域背景
颜色。更复杂的内容可以通过子类化UIView和
来实现必要的绘图和
事件处理代码来呈现

UIKit框架还包括一组可以使用的
标准子类,其中
的范围从简单按钮到复杂
表。例如,UILabel对象
绘制一个文本字符串,UIImageView
对象绘制一个图像。

The UIView class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content. The UIView class itself provides basic behavior for filling its rectangular area with a background color. More sophisticated content can be presented by subclassing UIView and implementing the necessary drawing and event-handling code yourself. The UIKit framework also includes a set of standard subclasses you can use, which range from simple buttons to complex tables. For example, a UILabel object draws a text string and a UIImageView object draws an image.

因为你的应用程序交互
用户主要通过查看
对象,这些对象有一个数字
的责任。这里只是一些

Because your application interacts with the user primarily through view objects, those objects have a number of responsibilities. Here are just a few:

绘图和动画视图使用
技术,如UIKit在其矩形区域绘制
内容, Core
Graphics和OpenGL ES。一些视图
属性可以动画到新的
值。布局和子视图管理
视图可能包含零个或多个
子视图。每个视图定义它自己的
默认调整大小行为,关联
到其父视图。视图可以根据需要手动更改其子视图的大小和位置
。事件
处理一个视图是一个响应者,可以
处理触发事件和UIResponder类定义的其他事件
。 A
视图可以使用addGestureRecognizer:
方法来安装手势识别器
来处理常见手势。

Drawing and animation A view draws content in its rectangular area using technologies such as UIKit, Core Graphics, and OpenGL ES. Some view properties can be animated to new values. Layout and subview management A view may contain zero or more subviews. Each view defines its own default resizing behavior in relation to its parent view. A view can manually change the size and position of its subviews as needed. Event handling A view is a responder and can handle touch events and other events defined by the UIResponder class. A view can use the addGestureRecognizer: method to install gesture recognizers to handle common gestures.

UIViewController

UIViewController


UIViewController类为iPhone应用程序提供了
基本视图管理模型
。基本的
视图控制器类支持关联视图的
演示,
支持管理模态视图,
支持旋转视图以响应
到设备方向更改。
子类如
UINavigationController和
UITabBarController为管理复杂的
视图控制器层次结构和
视图提供额外的
行为。

The UIViewController class provides the fundamental view-management model for iPhone applications. The basic view controller class supports the presentation of an associated view, support for managing modal views, and support for rotating views in response to device orientation changes. Subclasses such as UINavigationController and UITabBarController provide additional behavior for managing complex hierarchies of view controllers and views.

您使用
UIViewController的每个实例来管理视图
层次结构。典型的视图层次结构
由根视图组成 - 对
的引用,它在此类的视图
属性中可用 - 通常一个
或更多子视图呈现实际
内容。在iPhone和iPod touch上,
根视图通常填充整个
屏幕,但是在iPad上,这个视图可能只填充
只有屏幕的一部分。在两个
情况下,视图控制器是
,负责管理整个
视图层次结构,包括所有
子视图。

You use each instance of UIViewController to manage a view hierarchy. A typical view hierarchy consists of a root view—a reference to which is available in the view property of this class—and usually one or more subviews presenting the actual content. On iPhone and iPod touch, the root view typically fills the entire screen but on iPad this view may fill only part of the screen. In both cases, the view controller is responsible for managing the entire view hierarchy, including all subviews.

视图控制器紧紧绑定到
他们管理的视图,并参与
响应器链用于处理
事件。视图控制器是
本身是
UIResponder类的后代,并且将
插入到
管理的根视图及其超级视图之间的响应链中
通常属于不同的
视图控制器。如果视图
控制器的视图不处理
事件,视图控制器本身有
处理事件
的选项,然后将事件传递到
superview 。

View controllers are tightly bound to the views they manage and take part in the responder chain used to handle events. View controllers are themselves descendants of the UIResponder class and are inserted into the responder chain between the managed root view and its superview, which typically belongs to a different view controller. If the view controller’s view does not handle an event, the view controller itself has the option of handling the event before passing the event along to the superview.

UIViewController类使用
应用程序的窗口来处理
设备方向更改。如果
视图控制器支持新的
方向(由其
返回值确定的
的shouldAutorotateToInterfaceOrientation:
方法),它动画转换
从当前的方向到
新的。作为此更改的一部分,
也适用于
效果中的任何调整大小规则对其视图
层次结构中的视图。如果你想要改变
到你的视图层次作为
方向更改的一部分,你可以覆盖
方法UIViewController到
实现您的更改。对于
关于
覆盖所需的方法的信息,请参阅处理视图
旋转。

The UIViewController class works with the application’s window to handle device orientation changes. If the view controller supports the new orientation (as determined by the return value of its shouldAutorotateToInterfaceOrientation: method), it animates the transition from the current orientation to the new one. As part of this change, it also applies any resizing rules in effect for the views in its view hierarchy. If you want to make changes to your view hierarchy as part of the orientation change, you can override methods of UIViewController to implement your changes. For information on the methods you need to override, see "Handling View Rotations."

视图控制器是
大多数iPhone
应用程序的设计。
后面的部分提供了有关使用
的基本信息
UIViewController类的方法和属性。有关使用视图
控制器构建和管理
应用程序的用户界面的额外
信息,请参阅View
iOS控制器编程指南。

View controllers are fundamental to the design of most iPhone applications. The sections that follow provide basic information about using the methods and properties of the UIViewController class. For additional information about using view controllers to build and manage your application’s user interface, see View Controller Programming Guide for iOS.

这篇关于视图和视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆