博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
源码03-02-03-04-UIWindow
阅读量:5249 次
发布时间:2019-06-14

本文共 6895 字,大约阅读时间需要 22 分钟。

 

自定义窗口,不使用系统的storyboard

 

 

////  main.m//  03-UIWindow#import 
#import "AppDelegate.h"int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }}// main -> UIApplicationMain/* UIApplicationMain 1.创建UIApplication 2.创建UIApplicationDelegate,并且成为UIApplication代理 3.开启主运行循环,保持程序一直在运行 4.加载info.plist,判断有没有指定main.stroyboard,指定了就加载 加载main.stroyboard做的事情 1.创建窗口 2.加载main.storyboard,并且加载main.storyboard指定的控制器 3.把新创建的控制器作为窗口的跟控制器,让窗口显示出来 */

 

////  AppDelegate.m//  03-UIWindow#import "AppDelegate.h"@interface AppDelegate ()@end@implementation AppDelegate// 程序启动完成的时候- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.        // 1.创建窗口,注意窗口必须要有尺寸,尺寸跟屏幕一样大的尺寸,窗口不要被释放    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];    self.window.backgroundColor = [UIColor redColor];        // 2.创建窗口的跟控制器    UIViewController *vc = [[UIViewController alloc] init];    vc.view.backgroundColor = [UIColor yellowColor];        [vc.view addSubview:[UIButton buttonWithType:UIButtonTypeContactAdd]];        // 如果设置窗口的跟控制器,默认就会把控制器的view添加到窗口上    // 设置窗口的跟控制器,默认就有旋转功能    self.window.rootViewController = vc;    //    [self.window addSubview:vc.view];//这种设置自控件是没有旋转功能的;        // 3.显示窗口    [self.window makeKeyAndVisible];        return YES;}- (void)applicationWillResignActive:(UIApplication *)application {    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application {    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application {    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application {    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application {    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end

 

 

04-UIWindow补充

//  AppDelegate.m//  04-UIWindow补充#import "AppDelegate.h"@interface AppDelegate ()@property (nonatomic, strong) UITextField *textField;@property (nonatomic, strong) UIWindow *window1;@end@implementation AppDelegate//- (void)setWindow:(UIWindow *)window//{//    _window = window;//    [UIApplication sharedApplication].windows//}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.        self.window1 = [[UIWindow alloc] initWithFrame:CGRectMake(50, 50, 250, 250)];        self.window1.backgroundColor = [UIColor yellowColor];        // 设置窗口的层级关系    self.window1.windowLevel = UIWindowLevelStatusBar;        [self.window1 makeKeyAndVisible];        // 窗口是有层级关系    // UIWindowLevelNormal < UIWindowLevelStatusBar < UIWindowLevelAlert        self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];    self.window.windowLevel = UIWindowLevelAlert;        self.window.backgroundColor = [UIColor redColor];        [self.window makeKeyAndVisible];                return YES;}- (void)keyboardIsWindow{    // 创建窗口    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];    self.window.backgroundColor = [UIColor yellowColor];        // 判断下键盘是不是窗口//    NSLog(@"%@",application.windows);    // 如何才能弹出键盘    // 如果需要看到键盘,必须要把textField添加到一个View上面    UITextField *textField = [[UITextField alloc] init];    _textField = textField;    [textField becomeFirstResponder];    [self.window addSubview:textField];    //    NSLog(@"%@",application.windows);        // 显示窗口    [self.window makeKeyAndVisible];}// 窗口:键盘,状态栏也是窗口#pragma mark - 窗口的显示- (void)windowWithVisible{    // 1.创建窗口    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];            //    self.window.backgroundColor = [UIColor greenColor];        // application.windows:只要一给delegate的window属性赋值,就会添加到windows数组。//    NSLog(@"%@",application.windows);        // 2.显示窗口    // makeKeyAndVisible:成为app的主窗口并且显示    [self.window makeKeyAndVisible];//    NSLog(@"%@",application.windows);    //    self.window.hidden = NO;    NSLog(@"%@",self.window);}- (void)applicationWillResignActive:(UIApplication *)application {    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application {    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application {    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application {    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application {    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end

 

转载于:https://www.cnblogs.com/laugh/p/6549393.html

你可能感兴趣的文章
【18】平衡二叉树
查看>>
转: ubuntu apt-get 与 aptitude 用法与区别
查看>>
基于ACE的TAO开发---一个简单的入门实例-----VS2008(一)
查看>>
数据库 阶段总结
查看>>
算法之【仿竖式算法】
查看>>
java环境安装说明
查看>>
Jmeter通过BeanShell Sampler获取Jmeter的Bin路径,并存入变量供后面的脚本调用
查看>>
MySQL Migration Toolkit v2.1特别版
查看>>
使用using current logfile实现DG备库实时更新
查看>>
List.Jion
查看>>
一段对16进制字符串进行异或的代码
查看>>
ubuntu设置环境变量
查看>>
C语言Huffman压缩和解压
查看>>
hihocoder1148 February 29(区间闰年计数)
查看>>
HDU-5533 Dancing Stars on Me
查看>>
为什么要用全文搜索引擎:全文搜索引擎 VS 数据库管理系统
查看>>
MySQL添加用户、删除用户与授权
查看>>
利用 DBHelper实现增加、删除、修改数据库字段功能
查看>>
Linux中常用的查看系统信息的命令
查看>>
Android获取手机和系统版本等信息的代码
查看>>