123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- //
- // GlobalImports.swift
- // TSLiveWallpaper
- //
- // Created by 100Years on 2024/12/20.
- //
- @_exported import Foundation
- @_exported import UIKit
- @_exported import SnapKit
- import AVFoundation
- public 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
- public 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;
- }
- /** 屏幕宽度 */
- public let k_ScreenWidth = UIScreen.main.bounds.size.width
- /** 屏幕高度 */
- public let k_ScreenHeight = UIScreen.main.bounds.size.height
- /* 导航栏高度 固定高度 = 44.0f */
- //let k_Height_NavContentBar :CGFloat = UINavigationBar.appearance().frame.size.height
- public let k_Height_NavBar :CGFloat = 44.0
- /** 状态栏高度 */
- public let k_Height_StatusBar :CGFloat = k_Height_statusBar()
- /** 状态栏+导航栏的高度 */
- public let k_Nav_Height: CGFloat = k_Height_NavBar + k_Height_StatusBar
- /** 底部tabBar栏高度(不包含安全区,即:在 iphoneX 之前的手机) */
- public let k_TabBar_Height :CGFloat = 49.0
- /** 底部导航栏高度(包括安全区),一般使用这个值 */
- public let k_Height_TabBar :CGFloat = k_Height_safeAreaInsetsBottom() + k_TabBar_Height
- // MARK: - 检查系统版本 -
- /* 检查系统版本 */
- /// 版本号相同:
- public func systemVersionEqual(version:String) -> Bool {
- return UIDevice.current.systemVersion == version
- }
- /// 系统版本高于等于该version 测试发现只能传入带一位小数点的版本号 不然会报错 具体原因待探究
- public func systemVersionGreaterThan(version:String) -> Bool {
- return UIDevice.current.systemVersion.compare(version, options: .numeric, range: version.startIndex..<version.endIndex, locale: Locale(identifier:version)) != ComparisonResult.orderedAscending
- }
- //判断是否是 x、及x以上 系列
- public func isIphoneX() -> Bool {
- return k_Height_safeAreaInsetsBottom() > 0.0; // 底部安全区 > 0 时,
-
- }
- //设计稿为 375*812 比例,所以比例系数为 375.0/kScreenWidth
- public let kDesignScale = k_ScreenWidth/375.0
- public func kGetUIH(designSize:CGSize,currentW:CGFloat) -> CGFloat {
- let scale = designSize.width/currentW
- return designSize.height/scale
- }
-
- 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 className(from object: Any) -> String {
- return String(describing: type(of: object))
- }
- public func appVersion() ->String{
- let short = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
- return "V" + short
- }
- /// 震动
- public func playVibration() {
- // 默认震动 kSystemSoundID_Vibrate
- // 1519 短震 3D Touch中的peek震动反馈
- // 1520 短震 3D Touch中的pop震动反馈
- // 1521 连续三次短震动
- // peek的震动反馈轻于pop
-
- let soundID: UInt32 = 1520
- AudioServicesPlaySystemSound(soundID)
- }
- 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)
- }
|