ios -- swift -- 侧滑返回时 页面卡住不动

本文介绍了在iOS开发中遇到侧滑返回时页面卡住的问题,通过禁用并重新设置interactivePopGestureRecognizer的使能状态,解决了该问题。在BaseNavigationController中,重写init方法并设置手势委托及导航控制器委托,确保在视图控制器数量大于1时才能进行侧滑返回操作。
// 
//	Part	001
//  
let purchaseOrderBillVC = PurchaseOrderBillViewController()
        let purchaseOrderBillNav = BaseNavigationController.init(rootViewController: purchaseOrderBillVC)
        purchaseOrderBillNav.interactivePopGestureRecognizer?.isEnabled = false
        
        let reportFormVC = ReportFormViewController()
        let reportFormNav = BaseNavigationController.init(rootViewController: reportFormVC)
        reportFormNav.interactivePopGestureRecognizer?.isEnabled = false

        let accountVC = AccountViewController()
        let accountNav = BaseNavigationController.init(rootViewController: accountVC)
        accountNav.interactivePopGestureRecognizer?.isEnabled = false

        let messageVC = MessageViewController()
        let messageNav = BaseNavigationController.init(rootViewController: messageVC)
        messageNav.interactivePopGestureRecognizer?.isEnabled = false

        let userVC = UserViewController()
        let userNav = BaseNavigationController.init(rootViewController: userVC)
        userNav.interactivePopGestureRecognizer?.isEnabled = false

        tabBar = UITabBarController()
        tabBar?.tabBar.backgroundColor = UIColor.white
        tabBar?.selectedIndex = 0
        tabBar?.viewControllers = [purchaseOrderBillNav,reportFormNav,accountNav,messageNav,userNav]
        window?.rootViewController = tabBar!
// 
//	Part	002
//
//
//  BaseNavigationController.swift
//  erp-mobile-supplier
//
//  Created by wxd on 2016/12/8.
//  Copyright © 2016年 ds365.com. All rights reserved.
//

import UIKit

class BaseNavigationController: UINavigationController {
    
    //MARK: - life
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    //MARK: - self
    
    override init(rootViewController: UIViewController) {
        super.init(rootViewController: rootViewController)
        
        self.interactivePopGestureRecognizer?.delegate = self as? UIGestureRecognizerDelegate
        self.delegate = self as UINavigationControllerDelegate
    }
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension BaseNavigationController: UINavigationControllerDelegate {
    
    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        
    }
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        
        if navigationController.viewControllers.count > 1 {
            self.interactivePopGestureRecognizer?.isEnabled = true
        }else {
            self.interactivePopGestureRecognizer?.isEnabled = false
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值