第一种, addchild ,但是 电池兰操控不了

1.创建一个 普通的viewController ,添加需要push的 UITabBarController

/// 添加TabController的控制器
class JYJokerThroughRootController: JYBaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        /// TabController
        let jokerThroughRootVC = JYJokerThroughTabController()
        self.addChild(jokerThroughRootVC)
        self.view.addSubview(jokerThroughRootVC.view)
        ///隐藏导航栏:不隐藏会出现两个导航栏,一个是push之前的tab的导航栏, 一个是push之后的tab的导航栏
        JYNavDelegateManager.shareManager.addHiddNavBarControllerType(of: JYJokerThroughRootController.self)
    }
}

 

2. 推荐使用 :直接push , 并且在JYJokerThroughTabController隐藏 他的导航栏

                let rootTabVC = JYJokerThroughTabController()
                rootTabVC.hidesBottomBarWhenPushed = true
                self.navigationController?.pushViewController( rootTabVC, animated: true)




JYJokerThroughTabController 的 viewDidLoad()  添加隐藏导航栏方法
    /// 初始化
    override func viewDidLoad() {
        super.viewDidLoad()
        JYNavDelegateManager.shareManager.addHiddNavBarControllerType(of: JYJokerThroughTabController.self)
        configUI()
    }

 

 

 

3. 如果新的tabBarController界面需要左上角显示返回按钮 , 可以自定义,pop的时候需要 用注意tabBarController?.navigationController进行pop, 不是 self.navigationController 进行pop

    private func testBack(){
        let backBtn = UIButton(type: UIButton.ButtonType.custom)
        backBtn.backgroundColor = UIColor.green
        backBtn.frame = CGRect(x: 0, y: 100, width: 100, height: 100)
        backBtn.setImage(UIImage.init(named: "back_normal_gray"), for: UIControl.State.normal)
        backBtn.addTarget(self, action: #selector(clcikBackBtn), for: UIControl.Event.touchUpInside)
        view.addSubview(backBtn)
    }




    @objc private func clcikBackBtn() {
        self.tabBarController?.navigationController?.popViewController(animated: true)
    }

 

 

4. 新的tabbarController 1级界面禁用手势, 不然和之前的导航栏手势冲突, 新的tab  push 多次之后,侧滑返回不是在新tab的 一次次返回,直接 返回到第一个tab上

    /// 是否允许收手势返回
    private var isCanSideBack: Bool = true


    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.forbidhenSideBack()
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.resetSideBack()
    }


// MARK: 一级界面禁止手势
extension JYJokerThroughHomeController: UIGestureRecognizerDelegate {
    
    /// 禁止使用手势返回
    func forbidhenSideBack() {
        self.isCanSideBack = false
        if (self.navigationController?.responds(to:#selector(getter: self.navigationController?.interactivePopGestureRecognizer))) == true {
            self.navigationController?.interactivePopGestureRecognizer?.delegate = self
        }
    }
    
    /// 恢复手势返回
    func resetSideBack() {
        self.isCanSideBack = true
        if (self.navigationController?.responds(to:#selector(getter: self.navigationController?.interactivePopGestureRecognizer))) == true {
            self.navigationController?.interactivePopGestureRecognizer?.delegate = nil
        }
    }
    
    /// 是否禁用手势
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return self.isCanSideBack
    }
}

 

posted on 2020-06-30 17:00  懂事长qingzZ  阅读(473)  评论(0编辑  收藏  举报