From 1557c93bd6414d2ad3c70a26060dbe08d602d0f5 Mon Sep 17 00:00:00 2001 From: EyreFree Date: Mon, 27 Mar 2023 23:50:56 +0800 Subject: [PATCH] 1.6.0 --- EFFoundation.podspec | 2 +- EFFoundation/Core/EFFoundation.swift | 2 +- EFFoundation/Core/Extension/CGFloat+.swift | 4 ++-- EFFoundation/Core/Extension/Date+.swift | 4 ++-- .../Core/Extension/UIApplication+.swift | 6 +++--- EFFoundation/Core/Extension/UIFont+.swift | 6 +++--- .../Core/Extension/UIViewController+.swift | 18 ++++++++++++------ 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/EFFoundation.podspec b/EFFoundation.podspec index 54f1fb6..d3ca273 100644 --- a/EFFoundation.podspec +++ b/EFFoundation.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'EFFoundation' - s.version = '1.5.4' + s.version = '1.6.0' s.summary = 'EFFoundation.' s.description = <<-DESC diff --git a/EFFoundation/Core/EFFoundation.swift b/EFFoundation/Core/EFFoundation.swift index 16aac0b..56d70e9 100644 --- a/EFFoundation/Core/EFFoundation.swift +++ b/EFFoundation/Core/EFFoundation.swift @@ -12,7 +12,7 @@ import Foundation import UIKit public func hideKeyboard() { - UIApplication.shared?.keyWindow?.endEditing(true) + UIApplication.shared()?.keyWindow()?.endEditing(true) } #endif #endif diff --git a/EFFoundation/Core/Extension/CGFloat+.swift b/EFFoundation/Core/Extension/CGFloat+.swift index 8f2a436..4bf8ab6 100644 --- a/EFFoundation/Core/Extension/CGFloat+.swift +++ b/EFFoundation/Core/Extension/CGFloat+.swift @@ -18,9 +18,9 @@ public extension CGFloat { static let screenWidth: CGFloat = UIScreen.main.bounds.size.width static let screenHeight: CGFloat = UIScreen.main.bounds.size.height static let screenMinEdge: CGFloat = Swift.min(screenWidth, screenHeight) + static let topSafeAreaHeight: CGFloat = UIApplication.shared()?.keyWindow()?.safeAreaInsets.top ?? 0 + static let bottomSafeAreaHeight: CGFloat = UIApplication.shared()?.keyWindow()?.safeAreaInsets.bottom ?? 0 #endif - - static let navigationBarHeight: CGFloat = 44 var nsNumber: NSNumber { return NSNumber(value: self) diff --git a/EFFoundation/Core/Extension/Date+.swift b/EFFoundation/Core/Extension/Date+.swift index 113e824..9528873 100644 --- a/EFFoundation/Core/Extension/Date+.swift +++ b/EFFoundation/Core/Extension/Date+.swift @@ -12,8 +12,8 @@ public extension Date { func string(dateFormat: String = "yyyy-MM-dd HH:mm", timeZone: TimeZone = NSTimeZone.local, locale: Locale = Locale.current) -> String { let dateFormatter: DateFormatter = DateFormatter() dateFormatter.dateFormat = dateFormat - dateFormatter.timeZone = NSTimeZone.local - dateFormatter.locale = Locale.current + dateFormatter.timeZone = timeZone + dateFormatter.locale = locale return dateFormatter.string(from: self) } diff --git a/EFFoundation/Core/Extension/UIApplication+.swift b/EFFoundation/Core/Extension/UIApplication+.swift index 34979ec..ea112fd 100644 --- a/EFFoundation/Core/Extension/UIApplication+.swift +++ b/EFFoundation/Core/Extension/UIApplication+.swift @@ -23,17 +23,17 @@ public extension UIApplication { return isAppExtension }() - static let shared: UIApplication? = { + static func shared() -> UIApplication? { if isAppExtension { return nil } let selector = NSSelectorFromString("sharedApplication") guard UIApplication.responds(to: selector) else { return nil } return UIApplication.perform(selector).takeUnretainedValue() as? UIApplication - }() + } func keyWindow() -> UIWindow? { - guard let currentApplication = UIApplication.shared else { return nil } + let currentApplication = self var targetWindow = currentApplication.keyWindow if #available(iOS 13.0, tvOS 13.0, *) { let scenes = currentApplication.connectedScenes.filter({ $0.activationState == .foregroundActive }) diff --git a/EFFoundation/Core/Extension/UIFont+.swift b/EFFoundation/Core/Extension/UIFont+.swift index 9f288ca..7605d00 100644 --- a/EFFoundation/Core/Extension/UIFont+.swift +++ b/EFFoundation/Core/Extension/UIFont+.swift @@ -17,11 +17,11 @@ public extension UIFont { } static func pingFangSCUltralight(ofSize: CGFloat) -> UIFont { - return UIFont.init(name: "PingFangSC-Ultralight", size: ofSize) ?? UIFont.pingFangSCThin(ofSize: ofSize) + return UIFont.init(name: "PingFangSC-Ultralight", size: ofSize) ?? UIFont.pingFangSCRegular(ofSize: ofSize) } static func pingFangSCLight(ofSize: CGFloat) -> UIFont { - return UIFont.init(name: "PingFangSC-Light", size: ofSize) ?? UIFont.pingFangSCRegular(ofSize: ofSize) + return UIFont.init(name: "PingFangSC-Light", size: ofSize) ?? UIFont.pingFangSCUltralight(ofSize: ofSize) } static func pingFangSCThin(ofSize: CGFloat) -> UIFont { @@ -29,7 +29,7 @@ public extension UIFont { } static func pingFangSCMedium(ofSize: CGFloat) -> UIFont { - return UIFont.init(name: "PingFangSC-Medium", size: ofSize) ?? UIFont.pingFangSCRegular(ofSize: ofSize) + return UIFont.init(name: "PingFangSC-Medium", size: ofSize) ?? UIFont.pingFangSCThin(ofSize: ofSize) } static func pingFangSCSemibold(ofSize: CGFloat) -> UIFont { diff --git a/EFFoundation/Core/Extension/UIViewController+.swift b/EFFoundation/Core/Extension/UIViewController+.swift index d73ec3b..09598bb 100644 --- a/EFFoundation/Core/Extension/UIViewController+.swift +++ b/EFFoundation/Core/Extension/UIViewController+.swift @@ -10,17 +10,21 @@ import UIKit public extension UIViewController { - var topViewController: UIViewController { - return presentedViewController?.topViewController + static var rootViewController: UIViewController? { + return UIApplication.shared()?.keyWindow()?.rootViewController + } + + static var topViewController: UIViewController? { + return UIApplication.shared()?.keyWindow()?.rootViewController?.topViewController + } + + private var topViewController: UIViewController { + return self.presentedViewController?.topViewController ?? (self as? UITabBarController)?.selectedViewController?.topViewController ?? (self as? UINavigationController)?.visibleViewController?.topViewController ?? self } - static var topViewController: UIViewController { - return UIApplication.shared?.delegate?.window??.rootViewController?.topViewController ?? UIViewController() - } - func goBack(animated: Bool, completion: (() -> Void)? = nil) { if let navigationController = self.navigationController, navigationController.viewControllers.count > 1 { navigationController.popViewController(animated: animated) { [weak self] in @@ -29,6 +33,8 @@ public extension UIViewController { } } else if nil != self.presentingViewController { self.dismiss(animated: animated, completion: completion) + } else { + printLog("No need to goBack.") } } }