//
// JLAppDelegate.m
// 01-UIWindow
//
// Created by XinYou on 15-3-11.
// Copyright (c) 2015年 vxinyou. All rights reserved.
//
#import "JLAppDelegate.h"
@implementation
JLAppDelegate
-
(
BOOL
)
application:
(
UIApplication
*
)
application
didFinishLaunchingWithOptions:
(
NSDictionary
*
)
launchOptions
{
// 第1个window
self
.
window
=
[[
UIWindow
alloc
]
init
];
self
.
window
.
frame
=
[
UIScreen
mainScreen
].
bounds
;
self
.
window
.
backgroundColor
=
[
UIColor
redColor
];
// 让window成为keyWindow(主窗口),默认不可见
// [self.window makeKeyWindow];
// 让window成为keyWindow(主窗口),并且可见
[
self
.
window
makeKeyAndVisible
];
// 给第1个window添加一个输入框
UITextField
*
tf
=
[[
UITextField
alloc
]
init
];
tf
.
frame
=
CGRectMake
(
10
,
10
,
100
,
30
);
tf
.
borderStyle
=
UITextBorderStyleRoundedRect
;
[
self
.
window
addSubview
:
tf
];
// 打印当前应用的主窗口,此时应用的主窗口是window
NSLog
(
@"%p"
,
[
UIApplication
sharedApplication
].
keyWindow
);
// 第2个window
self
.
window2
=
[[
UIWindow
alloc
]
initWithFrame
:
CGRectMake
(
100
,
100
,
200
,
200
)];
self
.
window2
.
backgroundColor
=
[
UIColor
blueColor
];
// 让window2成为keyWindow(主窗口),并且可见。此时window将不再是主窗口,但是仍然能显示
[
self
.
window2
makeKeyAndVisible
];
// 给第2个window添加一个输入框
UITextField
*
tf2
=
[[
UITextField
alloc
]
init
];
tf2
.
frame
=
CGRectMake
(
50
,
50
,
70
,
40
);
tf2
.
borderStyle
=
UITextBorderStyleRoundedRect
;
[
self
.
window2
addSubview
:
tf2
];
// 打印当前应用的主窗口,此时window2已经成为了应用的主窗口
NSLog
(
@"%p"
,
[
UIApplication
sharedApplication
].
keyWindow
);
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