iOS开发

The Window

2016-02-29  本文已影响42人  Matcha00

window 创建与加载

创建

main windows 通过 Info.plist的 key “Main storyboard
file base name” ( UIMainStoryboardFile )加载Window
同时设置还window的delegate 属性 所有操作都在这个代理属性之前didFinishLaunchingWithOptions: 完成

加载

lazy var windows : UiWindow? ={
return MyWindow()
}

创建main windows

import UIKit
@UIApplicationMain
class AppDelegate : UIResponder, UIApplicationDelegate {
var window : UIWindow?
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {
self.window = UIWindow()
self.window!.rootViewController = UIViewController()
self.window!.backgroundColor = UIColor.whiteColor()
self.window!.makeKeyAndVisible()
return true
}
}

加载 main window

self.window = MyWindow()

获取window实例方式

let w = UIApplication.sharedApplication().delegate!.window!!
let w = (UIApplication.sharedApplication().delegate as! AppDelegate).window!
let w = UIApplication.sharedApplication().keyWindow!这种方法系统会创建临时window 把它作为application’s key window

上一篇 下一篇

猜你喜欢

热点阅读