https://github.com/potato512/SYSwiftLearning
UIWindow继承自UIView,用来管理和协调各种视图。提供一个区域来显示视图,将事件event分发给视图。
每个iOS应用必须包含一个window用于展示APP的交互页面, 且一个APP通常只有一个UIWindow,包含了APP的可视内容。
显示优先级,通常会有三个值,优先级顺序为:
UIWindowLevelAlert > UIWindowLevelStatusBar > UIWindowLevelnormal
(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 } }
原文地址:https://www.jb51.cc/swift/322755.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。