宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
//  LD_Def.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/2/28.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import Foundation
// MARK: -- Function
///当前的VC
public func LD_currentViewController() -> UIViewController {
    var currVC:UIViewController?
    var Rootvc = UIApplication.shared.keyWindow?.rootViewController
    repeat {
        if (Rootvc?.isKind(of: NSClassFromString("UINavigationController")!))! {
            let nav = Rootvc as! UINavigationController
            let v = nav.viewControllers.last
            currVC = v
            Rootvc = v?.presentedViewController
            continue
        }else if (Rootvc?.isKind(of: NSClassFromString("UITabBarController")!))!{
            let tabVC = Rootvc as! UITabBarController
            currVC = tabVC
            Rootvc = tabVC.viewControllers?[tabVC.selectedIndex]
            continue
        }else {
            return currVC!
        }
 
    } while Rootvc != nil
    return currVC!
}
 
///当前的NavVC
public func LD_currentNavigationController() -> UINavigationController {
    return LD_currentViewController().navigationController!
}
 
//MARK: - 加载xib视图
public protocol LDNibView{}
 
public extension LDNibView where Self : UIView{
 
    @discardableResult
    ///加载方式不同:用于非pod项目中,加载xib所使用
    public static func ld_loadNibView() -> Self {
        return Bundle.main.loadNibNamed(Mirror(reflecting: self).description.replacingOccurrences(of: "Mirror for", with: "").replacingOccurrences(of: ".Type", with: "").trimmingCharacters(in: CharacterSet.whitespaces), owner: nil, options: nil)?.first as! Self
    }
}