iOS UIKit :UIWindow
iOS UIKit :UIWindow
UIQWindow定义了一个window对象来管理views。一个软件只能有一个window。window的主要职能使为view提供显示取和向view传递事件。想要改变软件显示的内容,你可以改变window的root view。
UIWindow的screen属性指定了window的显示属性包括: bounds, mode, and brightness.
window notifications用来监听 window 和 screen的 改变,包括:
UIWindowDidBecomeVisibleNotification UIWindowDidBecomeHiddenNotification UIWindowDidBecomeKeyNotification UIWindowDidResignKeyNotification
UIWindow继承自UIView,关于这一点可能有点逻辑障碍,画框怎么继承自画布呢?不要过于去专牛角尖,画框的形状不就是跟画布一样吗?拿一块画布然后用一些方法把它加强,是不是可以当一个画框用呢?这也是为什么 一个view可以直接加到另一个view上去的原因了。 一个应用程序只能有一个画框。
看一下系统的初始化过程(在application didFinishLauchingWithOptions里面):
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary * )launchOptions { UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; myViewController = [[MyViewController alloc] init]; window.rootViewController = myViewController; [window makeKeyAndVisible]; return YES; }
创建一个 an external display:
- ( void )checkForExistingScreenAndInitializeIfPresent { if ([[UIScreen screens] count] > 1 ) { // Get the screen object that represents the external display. UIScreen *secondScreen = [[UIScreen screens] objectAtIndex: 1 ]; // Get the screen's bounds so that you can create a window of the correct size. CGRect screenBounds = secondScreen.bounds; self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds]; self.secondWindow.screen = secondScreen; // Set up initial content to display... // Show the window. self.secondWindow.hidden = NO; } } - ( void )setUpScreenConnectionNotificationHandlers { NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(handleScreenDidConnectNotification:) name:UIScreenDidConnectNotification object :nil]; [center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:) name:UIScreenDidDisconnectNotification object :nil]; } - ( void )handleScreenDidConnectNotification:(NSNotification* )aNotification { UIScreen *newScreen = [aNotification object ]; CGRect screenBounds = newScreen.bounds; if (! self.secondWindow) { self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds]; self.secondWindow.screen = newScreen; // Set the initial UI for the window. } } - ( void )handleScreenDidDisconnectNotification:(NSNotification* )aNotification { if (self.secondWindow) { // Hide and then delete the window. self.secondWindow.hidden = YES; self.secondWindow = nil; } }
分类: iOS
标签: iOSUIKit
作者: Leo_wl
出处: http://www.cnblogs.com/Leo_wl/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
版权信息查看更多关于iOS UIKit :UIWindow的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did45631