UI基础UIWindow、UIView

在PC中,应用程序多是使用视窗的形式显示内容,手机应用也不例外,手机应用中要在屏幕上显示内容首先要创建一个窗口承载内容,iOS应用中使用UIWindow、UIView来实现内容显示。

UIWindow:

UIWindow对象是所有UIView的根视图,管理和协调的应用程序的显示、分发事件给View。UIWindow类是UIView的子类,可以看作是特殊的UIView。一般应用程序只有一个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,负责在屏幕上 定义一个矩形区域,视图用于展示界面及响应用户界面交互。每个视图对象都要负责渲染视图区域的内容,并响应该区域中发生的操作事件。

除了显示内容和处理事件之外,视图可以嵌套并管理子视图。子视图是指嵌入到另一视图对象内部的视图对象,而被嵌入的视图对象是父视图。视图添加到window中就会显示出来,iOS中是怎么实现视图显示的,看下面的代码:

- (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中。

最新文章

  1. 第63课 C语言异常处理
  2. Delphi的内存管理及内存泄露问题 FastMM4
  3. 在PeopleSoft系统中实现打印页面的功能
  4. bzoj 3165: [Heoi2013]Segment 动态凸壳
  5. sql server和my sql 命令(语句)的差别,sql server与mysql的比較
  6. MYSQL查看和修改存储引擎
  7. leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法
  8. POJ1679(次小生成树)
  9. 一个Flask运行分析
  10. (六)List All Indices
  11. 项目之初的模型设计与status状态字段
  12. P2577 [ZJOI2005]午餐 状压DP
  13. 使用python爬虫爬取股票数据
  14. 解决java网络编程IPv6问题
  15. pl/sql中误删表中数据并提交恢复办法
  16. sphinx文档
  17. Hive学习之路 (二十)Hive 执行过程实例分析
  18. 跟我学算法-图像识别之图像分类(上)(基础神经网络, 卷积神经网络(CNN), AlexNet,NIN, VGG)
  19. WP的万能小应用时钟表
  20. Oracle-AWR报告简介及如何生成【转】

热门文章

  1. SQL表连接
  2. MVC5控制器、路由、返回类型、选择器、过滤器
  3. 创建GitHub技术博客
  4. [Openstack] Expecting an auth URL via either --os-auth-url or env[OS_AUTH_URL]
  5. NetMQ
  6. 面向对象JS基础讲解,工厂模式、构造函数模式、原型模式、混合模式、动态原型模式
  7. Kindle使用技巧
  8. 间支付系统,DataGridView
  9. Ubuntu中改变文件的默认打开方式
  10. nginx 502 Bad Gateway 错误问题收集