Screens, Windows, Views
Figure 1-1 A window with its target screen and contentviews
There are three major objects at work here:
l A UIScreen object that identifies a physical screen connected tothe device.
l A UIWindow object that provides drawing support for the screen.
l A set of UIView objects to perform the drawing. Theseobjects are attached to the window and draw their contents when the window asksthem to.
Figure 1-2 shows how these classes (and related importantclasses) are defined in UIKit.
Figure 1-2 Classes in theview system
Views的特点:
l 一个视图代表一下用户交互元素,每个视图覆盖一个特定的区域。在这个区域中,视图显示和响应动作事件。UIView是从UIResponder继承的。
l 视图之间可以有父子层次关系。子视图在父视图内显示,这样父视图移动,子视图也会跟着移动
l 视图具有很强的模块化,与Controller和Model两边之间低耦合。当用户和视图所在区域交互,视图发送通知给Controller,但它并不知道它们响应在程序是做什么具体内容。
视图控制器管理视图
一个视图控制器管理一个视图,这个可能是有一堆子视图的根视图。
Figure 1-3 Aview controller attached to a window automatically adds its view as a subviewof the window
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
窗口获取screen大小
给window设置根视图控制器,viewController会自动创建UIView视图。然后再显示。这是一个应用委托主要做的事情。
Figure1-5 View controller classes in UIKit
视图控制器分为内容视图控制器(content viewcontrollers)与容器视图控制器(container viewcontrollers)
内容视图控制器管理内容显示
容器视图控制器管理部署内容视图控制器