mirror of https://github.com/xaoxuu/ProHUD
自动获取根控制器和windowScene
This commit is contained in:
parent
03eebc6c93
commit
639dab2db0
|
@ -32,7 +32,7 @@
|
||||||
CD8BFF1B23014867001E08DD /* TestGuardVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestGuardVC.swift; sourceTree = "<group>"; };
|
CD8BFF1B23014867001E08DD /* TestGuardVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestGuardVC.swift; sourceTree = "<group>"; };
|
||||||
CD8BFF1D230148DD001E08DD /* BaseListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseListVC.swift; sourceTree = "<group>"; };
|
CD8BFF1D230148DD001E08DD /* BaseListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseListVC.swift; sourceTree = "<group>"; };
|
||||||
CD8BFF1F23014CB5001E08DD /* EmptyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyVC.swift; sourceTree = "<group>"; };
|
CD8BFF1F23014CB5001E08DD /* EmptyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyVC.swift; sourceTree = "<group>"; };
|
||||||
CDA4E03820D3935B00CD2A0C /* ProHUD (Xcode11之前的老项目).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ProHUD (Xcode11之前的老项目).app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
CDA4E03820D3935B00CD2A0C /* ProHUD 老项目.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ProHUD 老项目.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
CDA4E03B20D3935B00CD2A0C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
CDA4E03B20D3935B00CD2A0C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
CDA4E03D20D3935B00CD2A0C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
CDA4E03D20D3935B00CD2A0C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||||
CDA4E04020D3935B00CD2A0C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
CDA4E04020D3935B00CD2A0C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
CDA4E03920D3935B00CD2A0C /* Products */ = {
|
CDA4E03920D3935B00CD2A0C /* Products */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
CDA4E03820D3935B00CD2A0C /* ProHUD (Xcode11之前的老项目).app */,
|
CDA4E03820D3935B00CD2A0C /* ProHUD 老项目.app */,
|
||||||
);
|
);
|
||||||
name = Products;
|
name = Products;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -127,7 +127,7 @@
|
||||||
);
|
);
|
||||||
name = Example;
|
name = Example;
|
||||||
productName = Example;
|
productName = Example;
|
||||||
productReference = CDA4E03820D3935B00CD2A0C /* ProHUD (Xcode11之前的老项目).app */;
|
productReference = CDA4E03820D3935B00CD2A0C /* ProHUD 老项目.app */;
|
||||||
productType = "com.apple.product-type.application";
|
productType = "com.apple.product-type.application";
|
||||||
};
|
};
|
||||||
/* End PBXNativeTarget section */
|
/* End PBXNativeTarget section */
|
||||||
|
@ -383,7 +383,7 @@
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 2.0;
|
MARKETING_VERSION = 2.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample;
|
PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample;
|
||||||
PRODUCT_NAME = "ProHUD (Xcode11之前的老项目)";
|
PRODUCT_NAME = "ProHUD 老项目";
|
||||||
PROVISIONING_PROFILE = "b32d51a3-c20b-408f-aebf-11d2ea3811cd";
|
PROVISIONING_PROFILE = "b32d51a3-c20b-408f-aebf-11d2ea3811cd";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h";
|
||||||
|
@ -409,7 +409,7 @@
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 2.0;
|
MARKETING_VERSION = 2.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample;
|
PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample;
|
||||||
PRODUCT_NAME = "ProHUD (Xcode11之前的老项目)";
|
PRODUCT_NAME = "ProHUD 老项目";
|
||||||
PROVISIONING_PROFILE = "b32d51a3-c20b-408f-aebf-11d2ea3811cd";
|
PROVISIONING_PROFILE = "b32d51a3-c20b-408f-aebf-11d2ea3811cd";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h";
|
||||||
|
|
|
@ -22,14 +22,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
window = UIWindow.init(frame: UIScreen.main.bounds)
|
window = UIWindow.init(frame: UIScreen.main.bounds)
|
||||||
window?.rootViewController = vc
|
window?.rootViewController = vc
|
||||||
window?.makeKeyAndVisible()
|
window?.makeKeyAndVisible()
|
||||||
|
|
||||||
ProHUD.config { (cfg) in
|
ProHUD.config { (cfg) in
|
||||||
cfg.rootViewController = vc
|
// 可自动获取根控制器,如果获取失败请主动设置此值
|
||||||
if #available(iOS 13.0, *) {
|
// cfg.rootViewController = vc
|
||||||
cfg.windowScene = window?.windowScene
|
|
||||||
} else {
|
|
||||||
// Fallback on earlier versions
|
|
||||||
}
|
|
||||||
cfg.alert { (a) in
|
cfg.alert { (a) in
|
||||||
a.titleFont = .bold(22)
|
a.titleFont = .bold(22)
|
||||||
a.bodyFont = .regular(17)
|
a.bodyFont = .regular(17)
|
||||||
|
|
|
@ -15,7 +15,7 @@ class ViewController: BaseListVC {
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
// Do any additional setup after loading the view.
|
// Do any additional setup after loading the view.
|
||||||
title = "ProHUD"
|
title = "\(Bundle.main.infoDictionary?["CFBundleName"] ?? "ProHUD")"
|
||||||
}
|
}
|
||||||
|
|
||||||
override var titles: [String] {
|
override var titles: [String] {
|
||||||
|
|
|
@ -95,7 +95,7 @@ public extension Alert {
|
||||||
window.resignKey()
|
window.resignKey()
|
||||||
window.addSubview(view)
|
window.addSubview(view)
|
||||||
if #available(iOS 13.0, *) {
|
if #available(iOS 13.0, *) {
|
||||||
window.windowScene = cfg.windowScene
|
window.windowScene = cfg.windowScene ?? UIApplication.shared.windows.last?.windowScene
|
||||||
} else {
|
} else {
|
||||||
// Fallback on earlier versions
|
// Fallback on earlier versions
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ public extension Guard {
|
||||||
/// 推入某个视图控制器
|
/// 推入某个视图控制器
|
||||||
/// - Parameter viewController: 视图控制器
|
/// - Parameter viewController: 视图控制器
|
||||||
@discardableResult func push(to viewController: UIViewController? = nil) -> Guard {
|
@discardableResult func push(to viewController: UIViewController? = nil) -> Guard {
|
||||||
func f(_ vc: UIViewController) {
|
func f(_ vc: UIViewController) -> Guard {
|
||||||
view.layoutIfNeeded()
|
view.layoutIfNeeded()
|
||||||
vc.addChild(self)
|
vc.addChild(self)
|
||||||
vc.view.addSubview(view)
|
vc.view.addSubview(view)
|
||||||
|
@ -114,10 +114,25 @@ public extension Guard {
|
||||||
UIView.animateForGuard {
|
UIView.animateForGuard {
|
||||||
self.privTranslateIn()
|
self.privTranslateIn()
|
||||||
}
|
}
|
||||||
|
return self
|
||||||
}
|
}
|
||||||
if let vc = viewController ?? cfg.rootViewController {
|
if let vc = viewController ?? cfg.rootViewController {
|
||||||
f(vc)
|
return f(vc)
|
||||||
} else {
|
} else {
|
||||||
|
// 尝试获取RootVC
|
||||||
|
let ws = UIApplication.shared.windows.reversed().filter { (w) -> Bool in
|
||||||
|
// 去除掉诸如 UITextEffectsWindow 这样的类,去掉隐藏的Window
|
||||||
|
if "\(type(of:w))" == "UIWindow" && w.isHidden == false {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for w in ws {
|
||||||
|
if let vc = w.rootViewController {
|
||||||
|
return f(vc)
|
||||||
|
}
|
||||||
|
}
|
||||||
debug("请传入需要push到的控制器")
|
debug("请传入需要push到的控制器")
|
||||||
}
|
}
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -109,19 +109,19 @@ public extension Toast {
|
||||||
let config = cfg.toast
|
let config = cfg.toast
|
||||||
let isNew: Bool
|
let isNew: Bool
|
||||||
if self.window == nil {
|
if self.window == nil {
|
||||||
let w = UIWindow(frame: .zero)
|
let window = UIWindow(frame: .zero)
|
||||||
self.window = w
|
self.window = window
|
||||||
if #available(iOS 13.0, *) {
|
if #available(iOS 13.0, *) {
|
||||||
w.windowScene = cfg.windowScene
|
window.windowScene = cfg.windowScene ?? UIApplication.shared.windows.last?.windowScene
|
||||||
} else {
|
} else {
|
||||||
// Fallback on earlier versions
|
// Fallback on earlier versions
|
||||||
}
|
}
|
||||||
w.windowLevel = UIWindow.Level(5000)
|
window.windowLevel = UIWindow.Level(5000)
|
||||||
w.backgroundColor = .clear
|
window.backgroundColor = .clear
|
||||||
w.layer.shadowRadius = 8
|
window.layer.shadowRadius = 8
|
||||||
w.layer.shadowOffset = .init(width: 0, height: 5)
|
window.layer.shadowOffset = .init(width: 0, height: 5)
|
||||||
w.layer.shadowOpacity = 0.2
|
window.layer.shadowOpacity = 0.2
|
||||||
w.isHidden = false
|
window.isHidden = false
|
||||||
isNew = true
|
isNew = true
|
||||||
} else {
|
} else {
|
||||||
isNew = false
|
isNew = false
|
||||||
|
|
Loading…
Reference in New Issue