iOS-UIScreen,UIView,UIWindow和UIViewController的介绍和区别
来源:互联网 发布:2016年网络购物数据 编辑:程序博客网 时间:2024/04/28 11:57
一、参考
View Programming Guide for iOS
http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/Introduction/Introduction.html
View Controller Programming Guide for iOS
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html
UIScreen Class Reference
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIScreen_Class/Reference/UIScreen.html
UIView Class Reference
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html
UIWindow Class Reference
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html
UIViewController Class Reference
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html
二、区别
1、UIScreen可以获取设备屏幕的大小。
// 整个屏幕的大小 {{0, 0}, {320, 480}}CGRect bounds = [UIScreen mainScreen].bounds;NSLog(@"UIScreen bounds: %@", NSStringFromCGRect(bounds));// 应用程序窗口大小 {{0, 20}, {320, 460}}CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;NSLog(@"UIScreen applicationFrame: %@", NSStringFromCGRect(applicationFrame));
应用程序窗口大小 {{0, 20}, {320, 460}}
2、UIView对象定义了一个屏幕上的一个矩形区域,同时处理该区域的绘制和触屏事件。
可以在这个区域内绘制图形和文字,还可以接收用户的操作。一个UIView的实例可以包含和管理若干个子UIView。
ViewController.m
- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)]; myView.backgroundColor=[UIColor redColor]; [self.view addSubview:myView];}
3、UIWindow对象是所有UIView的根,管理和协调的应用程序的显示
UIWindow类是UIView的子类,可以看作是特殊的UIView。一般应用程序只有一个UIWindow对象,即使有多个UIWindow对象,也只有一个UIWindow可以接受到用户的触屏事件。
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ UIWindow *myWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; myWindow.backgroundColor=[UIColor whiteColor]; [myWindow makeKeyAndVisible]; _window = myWindow; returnYES;}
4、UIViewController对象负责管理所有UIView的层次结构,并响应设备的方向变化。
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ UIWindow *myWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; myWindow.backgroundColor=[UIColor whiteColor]; UIViewController *myViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil]; myWindow.rootViewController = myViewController; [myWindow makeKeyAndVisible]; _window = myWindow; returnYES;}
三、完整的代码
// ViewController.h#import <UIKit/UIKit.h>@interface ViewController : UIViewController@end// ViewController.m#import "ViewController.h"@implementation ViewController- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)]; myView.backgroundColor=[UIColor redColor]; [self.view addSubview:myView];}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { returnYES;}@end// AppDelegate.h#import <UIKit/UIKit.h>@classViewController;@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@property (strong, nonatomic) ViewController *viewController;@end// AppDelegate.m#import "AppDelegate.h"#import "ViewController.h"@implementation AppDelegate@synthesize window = _window;@synthesize viewController = _viewController;- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; returnYES;}@end// main.m#import <UIKit/UIKit.h>#import "AppDelegate.h"intmain(intargc, char*argv[]) { @autoreleasepool { returnUIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }}
- iOS-UIScreen,UIView,UIWindow和UIViewController的介绍和区别
- UIScreen,UIView,UIWindow和UIViewController的介绍和区别
- UIScreen,UIView,UIWindow和UIViewController的介绍和区别
- UIScreen,UIView,UIWindow和UIViewController的介绍和区别
- UIScreen,UIView,UIWindow和UIViewController的介绍和区别(转载)
- IOS开发中的UIScreen、UIView、UIWindow和UIViewController
- IOS开发中的UIScreen、UIView、UIWindow和UIViewController
- IOS开发中的UIScreen、UIView、UIWindow和UIViewController
- IOS开发中的UIScreen、UIView、UIWindow和UIViewController
- IOS开发中的UIScreen、UIView、UIWindow和UIViewController
- IOS开发中的UIScreen、UIView、UIWindow和UIViewController
- IOS开发之UIScreen和UIWindow,UIView
- iOS 关于UIScreen和UIWindow,UIView
- UIApplication、UIView、UIWindow、UIScreen、UIViewController、UINavigationController 介绍
- UIWindow UIScreen UIViewController UIView之间的关系
- UIWindow, UIView和UIViewController
- iOS开发--UIScreen,UIWindow和UIView
- IOS中 UIView和UIViewController的区别
- HDU 3973 AC's String(hash+线段树)
- HDU1754 - I Hate It (基础线段树)
- Trump成功笔记2
- Java类加载及变量初始化过程
- 使用PHPstorm连接svn问题记录(4):svn commit(简写:svn ci)svn: E205007
- iOS-UIScreen,UIView,UIWindow和UIViewController的介绍和区别
- HDU5443 - The Water Problem (线段树)
- ckeditor取值问题 前台+后台 取值方法
- HDU5444 - Elven Postman (树的遍历)
- CVGTalk-Tom-20151007
- 逆传------通知的方法
- HDU1698 - Just a Hook (线段树 区间更新)
- VC编程工具的灵活使用2
- 学习规划