向后滑动隐藏一些swift中的导航项

时间:2017-11-27 06:19:31

标签: ios navigationitem

我有一个关于swift滑动后退手势的问题。在父uicollectionviewcontroller处按下某个单元格后,我按下新的uicollectionviewcontroller后,我滑回到父视图控制器。但导航栏上只显示几个导航项目。但是,当我按“返回”按钮返回时,会显示所有导航项目。这是我的代码:

override func viewDidLoad() {
         setupNavBarButtons()}

func setupNavBarButtons(){
    let flexible = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: self, action: nil)
    flexible.isEnabled = false
    let logoImg = UIImage(named: "wee")?.withRenderingMode(.alwaysOriginal)
    let homeBarButtonItem = UIBarButtonItem(image:logoImg, style: .plain, target: self, action: #selector(handleHome))
    homeBarButtonItem.isEnabled = false
    let cameraImg = UIImage(named: "nav bar_circles")?.withRenderingMode(.alwaysOriginal)
    let cameraButtonItem = UIBarButtonItem(image:cameraImg, style: .plain, target: self, action: nil)

    cameraButtonItem.isEnabled = false
    navigationItem.rightBarButtonItems = [flexible, cameraButtonItem, flexible, cameraButtonItem, flexible, cameraButtonItem]
    navigationItem.leftBarButtonItems = [flexible, cameraButtonItem, flexible, cameraButtonItem, flexible, cameraButtonItem, flexible,  homeBarButtonItem]

    navigationItem.accessibilityElementsHidden = false

    navigationController?.hidesBarsOnSwipe = false
    navigationController?.isNavigationBarHidden = false


}

func showAppDetailForApp(pht: UIImage){

    let layout = UICollectionViewFlowLayout()
    let detailLauncher = ShowPhoto(collectionViewLayout: layout)
    detailLauncher.info = pht
    navigationController?.navigationBar.barTintColor = UIColor.white
    navigationController?.pushViewController(detailLauncher, animated: true)

}

提前致谢。

1 个答案:

答案 0 :(得分:0)

请在推送视图控制器的viewDidLoad()方法中设置以下代码行。

self.navigationController.interactivePopGestureRecognizer?.isEnabled = false