123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // GlobalImports.swift
- // KittensTravelNotes
- //
- // Created by 100Years on 2025/7/6.
- //
- @_exported import Foundation
- @_exported import UIKit
- @_exported import SnapKit
- func k_Height_statusBar() -> CGFloat {
- var statusBarHeight: CGFloat = 0;
- if #available(iOS 13.0, *) {
- let scene = UIApplication.shared.connectedScenes.first;
- guard let windowScene = scene as? UIWindowScene else {return 0};
- guard let statusBarManager = windowScene.statusBarManager else {return 0};
- statusBarHeight = statusBarManager.statusBarFrame.height;
- } else {
- statusBarHeight = UIApplication.shared.statusBarFrame.height;
- }
- return statusBarHeight;
- }
- /// ②、顶部安全区高度 k_Height_safeAreaInsetsTop
- func k_Height_safeAreaInsetsTop() -> CGFloat {
- if #available(iOS 13.0, *) {
- let scene = UIApplication.shared.connectedScenes.first;
- guard let windowScene = scene as? UIWindowScene else {return 0}; // guard:如果 expression 值计算为false,则执行代码块内的 guard 语句。(必须包含一个控制语句: return、 break、 continue 或 throw。)。as?:类型转换,(还有这两种:as、as!)
- guard let window = windowScene.windows.first else {return 0};
- return window.safeAreaInsets.top;
- } else if #available(iOS 11.0, *) {
- guard let window = UIApplication.shared.windows.first else {return 0};
- return window.safeAreaInsets.top;
- }
- return 0;
- }
- /// ③、底部安全区高度
- func k_Height_safeAreaInsetsBottom() -> CGFloat {
- if #available(iOS 13.0, *) {
- let scene = UIApplication.shared.connectedScenes.first;
- guard let windowScene = scene as? UIWindowScene else {return 0};
- guard let window = windowScene.windows.first else {return 0};
- return window.safeAreaInsets.bottom;
- } else if #available(iOS 11.0, *) {
- guard let window = UIApplication.shared.windows.first else {return 0};
- return window.safeAreaInsets.bottom;
- }
- return 0;
- }
- /** 屏幕宽度 */
- let k_ScreenWidth = UIScreen.main.bounds.size.width
- /** 屏幕高度 */
- let k_ScreenHeight = UIScreen.main.bounds.size.height
- /* 导航栏高度 固定高度 = 44.0f */
- //let k_Height_NavContentBar :CGFloat = UINavigationBar.appearance().frame.size.height
- let k_Height_NavBar :CGFloat = 44.0
- /** 状态栏高度 */
- let k_Height_StatusBar :CGFloat = k_Height_statusBar()
- /** 状态栏+导航栏的高度 */
- let k_Nav_Height: CGFloat = k_Height_NavBar + k_Height_StatusBar
- /** 底部tabBar栏高度(不包含安全区,即:在 iphoneX 之前的手机) */
- let k_TabBar_Height :CGFloat = 49.0
- /** 底部导航栏高度(包括安全区),一般使用这个值 */
- let k_Height_TabBar :CGFloat = k_Height_safeAreaInsetsBottom() + k_TabBar_Height
- public func debugPrint<T>(_ messsage: T, file: String = #file, funcName: String = #function, lineNum: Int = #line) {
- #if DEBUG
- let fileName = (file as NSString).lastPathComponent
- print(Date.hmsString + " \(fileName) (\(funcName)): [\(lineNum)]- \(messsage)")
- #endif
- }
- public func dePrint<T>(_ messsage: T) {
- #if DEBUG
- print(Date.hmsString + " \(messsage)")
- #endif
- }
- public func kPresentModalVC(target:UIViewController,
- modelVC:UIViewController,
- style:UIModalPresentationStyle = .overFullScreen,
- transitionStyle:UIModalTransitionStyle = .coverVertical,
- completion: (() -> Void)? = nil){
- let navi = TSBaseNavigationC(rootViewController: modelVC)
- navi.modalPresentationStyle = style
- navi.modalTransitionStyle = transitionStyle
- target.present(navi, animated: true,completion: completion)
- }
- public func kPushVC(target:UIViewController,modelVC:UIViewController){
- modelVC.hidesBottomBarWhenPushed = true
- target.navigationController?.pushViewController(modelVC, animated: true)
- }
- public func appShortVersion() ->String{
- let short = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
- return short
- }
- //设计稿为 375*812 比例,所以比例系数为 375.0/kScreenWidth
- let kDesignScale = k_ScreenWidth/375.0
|