https://github.com/potato512/SYSwiftLearning
UIWindow继承自UIView, 用来管理和协调各种视图。提供一个区域来显示视图, 将事件event分发给视图。
每个iOS应用必须包含一个window用于展示APP的交互页面, 且一个APP通常只有一个UIWindow, 包含了APP的可视内容。
显示优先级, 通常会有三个值, 优先级顺序为:
UIWindowLevelAlert > UIWindowLevelStatusBar > UIWindowLevelNormal
控制keyWindow的显示,隐藏方法
(1)显示:makeKeyAndVisible方法,及hiddin属性
(2)隐藏:resignKeyWindow方法,及hidden属性
效果图:
源码示例:
func alertClick()
{
// UIScreen.mainScreen().bounds
if self.alertWindow == nil
{
self.alertWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
self.alertWindow.windowLevel = UIWindowLevelAlert
self.alertWindow.backgroundColor = UIColor.yellowColor()
self.alertWindow.becomeKeyWindow()
let label = UILabel(frame: CGRectMake(10.0, 10.0, (CGRectGetWidth(self.alertWindow.frame) - 10.0 * 2), 180.0))
self.alertWindow.addSubview(label)
label.backgroundColor = UIColor.orangeColor()
label.numberOfLines = 0
label.font = UIFont.systemFontOfSize(13.0)
label.text = "UIWindow继承自UIView, 用来管理和协调各种视图。提供一个区域来显示视图, 将事件event分发给视图。\n每个iOS应用必须包含一个window用于展示APP的交互页面, 且一个APP通常只有一个UIWindow, 包含了APP的可视内容。\n显示优先级, 通常会有三个值, 优先级顺序为:UIWindowLevelAlert > UIWindowLevelStatusBar > UIWindowLevelNormal."
let button = UIButton(frame: CGRectMake((CGRectGetWidth(self.alertWindow.frame) - 10.0 - 80.0), (CGRectGetMinX(label.frame) + CGRectGetHeight(label.frame) + 10.0), 80.0, 30.0))
self.alertWindow.addSubview(button)
button.backgroundColor = UIColor.greenColor()
button.setTitle("hidden", forState: .Normal)
button.setTitleColor(UIColor.blackColor(), forState: .Normal)
button.setTitleColor(UIColor.redColor(), forState: .Highlighted)
button.addTarget(self, action: Selector("hiddenClick"), forControlEvents: .TouchUpInside)
}
self.alertWindow.makeKeyAndVisible()
self.alertWindow.hidden = false
}
func hiddenClick()
{
if self.alertWindow != nil
{
self.alertWindow.resignKeyWindow()
self.alertWindow.hidden = true
}
}
本文介绍了Swift中UIWindow的基本概念,它作为UIView的子类,负责管理和协调应用中的视图,并处理事件分发。每个iOS应用至少有一个UIWindow,通常用于展示APP内容。内容中提到了UIWindow的显示优先级以及控制keyWindow显示和隐藏的方法,包括makeKeyAndVisible、resignKeyWindow、hidden属性的使用。此外,还提供了源码示例。

1699

被折叠的 条评论
为什么被折叠?



