No Swipe Back when hiding Navigation Bar in UINavigationController

前端 未结 18 700
生来不讨喜
生来不讨喜 2020-12-04 06:34

I love the swipe pack thats inherited from embedding your views in a UINavigationController. Unfortunately i cannot seem to find a way to hide the Naviga

18条回答
  •  半阙折子戏
    2020-12-04 06:52

    In my view controller without navigationbar I use

    open override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)
    
      CATransaction.begin()
      UIView.animate(withDuration: 0.25, animations: { [weak self] in
        self?.navigationController?.navigationBar.alpha = 0.01
      })
      CATransaction.commit()
    }
    
    open override func viewWillDisappear(_ animated: Bool) {
      super.viewWillDisappear(animated)
      CATransaction.begin()
      UIView.animate(withDuration: 0.25, animations: { [weak self] in
        self?.navigationController?.navigationBar.alpha = 1.0
      })
      CATransaction.commit()
    }
    

    During the interactive dismissal the back button will shine through though, which is why I hid it.

提交回复
热议问题