Swift --棒棒糖4--判断当前的控制器是怎么来的

    extension UIViewController {
    
    
        var isModal: Bool {
    
    
            let presentingIsModal = presentingViewController != nil
            let presentingIsNavigation = navigationController?.presentingViewController?.presentedViewController == navigationController
            let presentingIsTabBar = tabBarController?.presentingViewController is UITabBarController
            
            return presentingIsModal || presentingIsNavigation || presentingIsTabBar
        }
    }
    你可以像这样写一个UIViewController的分类,也可以:
            var isModal: Bool {
    
    
            let presentingIsModal = presentingViewController != nil
            let presentingIsNavigation = navigationController?.presentingViewController?.presentedViewController == navigationController
            let presentingIsTabBar = tabBarController?.presentingViewController is UITabBarController
            
            return presentingIsModal || presentingIsNavigation || presentingIsTabBar
        }
这样单写一个属性,到你要查看怎么来的控制器里,即可,非常好使!

猜你喜欢

转载自blog.csdn.net/SoftwareDoger/article/details/106019503