在PC中,,應(yīng)用程序多是使用視窗的形式顯示內(nèi)容,,手機應(yīng)用也不例外,手機應(yīng)用中要在屏幕上顯示內(nèi)容首先要創(chuàng)建一個窗口承載內(nèi)容,,iOS應(yīng)用中使用UIWindow,、UIView來實現(xiàn)內(nèi)容顯示。 UIWindow: UIWindow對象是所有UIView的根視圖,,管理和協(xié)調(diào)的應(yīng)用程序的顯示,、分發(fā)事件給View。UIWindow類是UIView的子類,,可以看作是特殊的UIView,。一般應(yīng)用程序只有一個UIWindow對象,即使有多個UIWindow對象,,也只有一個UIWindow可以接受到用戶的觸屏事件,。UIWindow初始化在appDeleDgate里面的 didFinishLaunchingWithOptions方法,。
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- // Override point for customization after application launch.
- self.window.backgroundColor = [UIColor whiteColor];
- [self.window makeKeyAndVisible];//顯示出UIWindow
UIView: UIView類繼承自UIResponder,負責(zé)在屏幕上 定義一個矩形區(qū)域,,視圖用于展示界面及響應(yīng)用戶界面交互,。每個視圖對象都要負責(zé)渲染視圖區(qū)域的內(nèi)容,并響應(yīng)該區(qū)域中發(fā)生的操作事件,。 除了顯示內(nèi)容和處理事件之外,,視圖可以嵌套并管理子視圖。子視圖是指嵌入到另一視圖對象內(nèi)部的視圖對象,,而被嵌入的視圖對象是父視圖,。視圖添加到window中就會顯示出來,iOS中是怎么實現(xiàn)視圖顯示的,,看下面的代碼:
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
-
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- // Override point for customization after application launch.
- self.window.backgroundColor = [UIColor whiteColor];
-
-
- CGRect rect=[UIScreen mainScreen].applicationFrame;
-
- NSLog(@"NSScreen application %@",NSStringFromCGRect(rect));
- CGRect rect2=[UIScreen mainScreen].bounds;
-
- NSLog(@"NSString mainScreen %@",NSStringFromCGRect(rect2));
-
- NSLog(@"iOS_didFinishLaunchingWithOptions");
-
- UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(60, 50, 200, 100)];
- view1.backgroundColor=[UIColor greenColor];
-
- [self.window addSubview:view1];
- [view1 release];
-
- UIView *view2=[[UIView alloc]initWithFrame:CGRectMake(60, 100, 200, 200) ];
- view2.alpha=0.5;
- view2.backgroundColor=[UIColor cyanColor];
- [self.window addSubview:view2];
-
-
- UIView *view3=[[UIView alloc]initWithFrame:CGRectMake(100, 50, 60, 50)];
- view3.backgroundColor=[UIColor colorWithRed:25/255.0 green:60/255.0 blue:150/255.0 alpha:1.0];
- [view2 addSubview:view3];
-
- [view3 release];
- [view2 release];
-
- [self.window makeKeyAndVisible];
- return YES;
- }
上面添加了三個視圖,,view1、view2,、view3,,view3嵌套在view2中。
* iOS入門群:83702688
* android開發(fā)進階群:241395671 */
|