diff --git a/Sources/ProHUD/Alert/AlertManager.swift b/Sources/ProHUD/Alert/AlertManager.swift index 132a044..af367d4 100644 --- a/Sources/ProHUD/Alert/AlertManager.swift +++ b/Sources/ProHUD/Alert/AlertManager.swift @@ -70,11 +70,10 @@ public extension Alert { /// - Parameters: /// - identifier: 实例唯一标识符(如果为空,则以代码位置为唯一标识符) /// - handler: 实例创建代码 - static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ alert: Alert) -> Void) { + static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ alert: Alert) -> Void, onExists: ((_ alert: Alert) -> Void)? = nil) { let id = identifier ?? (file + "#\(line)") if let vc = AlertWindow.alerts.last(where: { $0.identifier == id }) { - handler(vc) - vc.reloadData() + onExists?(vc) } else { Alert { alert in alert.identifier = id diff --git a/Sources/ProHUD/Core/Views/ProgressView.swift b/Sources/ProHUD/Core/Views/ProgressView.swift index 3a6572e..e2d555d 100644 --- a/Sources/ProHUD/Core/Views/ProgressView.swift +++ b/Sources/ProHUD/Core/Views/ProgressView.swift @@ -58,14 +58,11 @@ public class ProgressView: UIView { } func updateProgress(progress: CGFloat) { - if progress <= 1 { - // 初始化 - if progressLayer.superlayer == nil { - progressLayer.strokeEnd = 0 - layer.addSublayer(progressLayer) - } - progressLayer.strokeEnd = progress + if progressLayer.superlayer == nil { + progressLayer.strokeEnd = 0 + layer.addSublayer(progressLayer) } + progressLayer.strokeEnd = max(min(progress, 1), 0) } } diff --git a/Sources/ProHUD/Sheet/SheetConvenienceLayout.swift b/Sources/ProHUD/Sheet/SheetConvenienceLayout.swift index 64c59d4..19805bb 100644 --- a/Sources/ProHUD/Sheet/SheetConvenienceLayout.swift +++ b/Sources/ProHUD/Sheet/SheetConvenienceLayout.swift @@ -145,10 +145,12 @@ public extension Sheet { contentStack.addArrangedSubview(lb) if #available(iOS 11.0, *) { let count = contentStack.arrangedSubviews.count - if count > 1 { - contentStack.setCustomSpacing(config.margin * 3, after: contentStack.arrangedSubviews[count-2]) + if count > 0 { contentStack.setCustomSpacing(config.margin * 1.5, after: contentStack.arrangedSubviews[count-1]) } + if count > 1 { + contentStack.setCustomSpacing(config.margin * 2, after: contentStack.arrangedSubviews[count-2]) + } } else { // Fallback on earlier versions } diff --git a/Sources/ProHUD/Sheet/SheetDefaultLayout.swift b/Sources/ProHUD/Sheet/SheetDefaultLayout.swift index 04317e7..89e01d2 100644 --- a/Sources/ProHUD/Sheet/SheetDefaultLayout.swift +++ b/Sources/ProHUD/Sheet/SheetDefaultLayout.swift @@ -81,16 +81,7 @@ extension Sheet: DefaultLayout { } else { make.top.equalToSuperview().offset(config.padding * 2) } - if width < maxWidth { - let bottom = screenSafeAreaInsets.bottom - if bottom == 0 { - make.bottom.equalToSuperview().inset(config.padding * 2) - } else { - make.bottom.equalToSuperview().inset(bottom - config.padding / 2) - } - } else { - make.bottom.equalToSuperview().inset(config.padding * 2) - } + make.bottom.equalToSuperview().inset(config.padding * 2) if isPortrait { make.left.right.equalToSuperview().inset(config.padding) } else { diff --git a/Sources/ProHUD/Sheet/SheetManager.swift b/Sources/ProHUD/Sheet/SheetManager.swift index 6cdd50c..2c6fd71 100644 --- a/Sources/ProHUD/Sheet/SheetManager.swift +++ b/Sources/ProHUD/Sheet/SheetManager.swift @@ -25,11 +25,10 @@ public extension Sheet { /// - Parameters: /// - identifier: 实例唯一标识符(如果为空,则以代码位置为唯一标识符) /// - handler: 实例创建代码 - static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ sheet: Sheet) -> Void) { + static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ sheet: Sheet) -> Void, onExists: ((_ sheet: Sheet) -> Void)? = nil) { let id = identifier ?? (file + "#\(line)") if let vc = find(identifier: id).last { - handler(vc) - vc.reloadData() + onExists?(vc) } else { Sheet { sheet in sheet.identifier = id diff --git a/Sources/ProHUD/Sheet/SheetWindow.swift b/Sources/ProHUD/Sheet/SheetWindow.swift index 942e741..061400f 100644 --- a/Sources/ProHUD/Sheet/SheetWindow.swift +++ b/Sources/ProHUD/Sheet/SheetWindow.swift @@ -15,9 +15,14 @@ class SheetWindow: Window { init(sheet: Sheet) { self.sheet = sheet - super.init(frame: .zero) if #available(iOS 13.0, *) { - windowScene = sheet.config.windowScene ?? UIApplication.shared.windows.last?.windowScene + if let scene = sheet.config.windowScene ?? UIApplication.shared.windows.last?.windowScene { + super.init(windowScene: scene) + } else { + super.init(frame: UIScreen.main.bounds) + } + } else { + super.init(frame: UIScreen.main.bounds) } sheet.window = self windowLevel = .init(rawValue: UIWindow.Level.alert.rawValue - 2) @@ -38,7 +43,7 @@ class SheetWindow: Window { window = SheetWindow(sheet: sheet) isNew = true } - window.rootViewController = sheet // 此时toast.view.frame.size会自动更新为window.frame.size + window.rootViewController = sheet if windows.contains(window) == false { windows.append(window) } diff --git a/Sources/ProHUD/Toast/ToastManager.swift b/Sources/ProHUD/Toast/ToastManager.swift index 1cb3cfe..2e4a804 100644 --- a/Sources/ProHUD/Toast/ToastManager.swift +++ b/Sources/ProHUD/Toast/ToastManager.swift @@ -25,11 +25,10 @@ public extension Toast { /// - Parameters: /// - identifier: 实例唯一标识符(如果为空,则以代码位置为唯一标识符) /// - handler: 实例创建代码 - static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ toast: Toast) -> Void) { + static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ toast: Toast) -> Void, onExists: ((_ toast: Toast) -> Void)? = nil) { let id = identifier ?? (file + "#\(line)") if let vc = find(identifier: id).last { - handler(vc) - vc.reloadData() + onExists?(vc) } else { Toast { toast in toast.identifier = id