Lan*_*ria 1 uinavigationbar uiviewcontroller uinavigationcontroller ios swift
一切都以编程方式进行。没有Storyboard,并且Collection视图的vc和详细的vc都在TabBarController中。
我正在使用集合视图,当我点击一个单元格时,didSelectItem我按下了一个详细的视图控制器。在DetailedVC中,我隐藏了导航控制器。我叫下面的viewDidLoad和viewWillAppear单独和累积,试图掩盖它:
navigationController?.isNavigationBarHidden = true
navigationController?.navigationBar.isHidden = true
navigationController?.setNavigationBarHidden(true, animated: false)
Run Code Online (Sandbox Code Playgroud)
场景首次出现时,导航栏被隐藏。问题是,当我在“ DetailedVC”上向下滑动时,导航栏会从屏幕顶部向下滑动,并且不会消失。我是通过误刷而发现的。
我按下导航栏的“后退”按钮,即使它应该隐藏也可以使用。我之所以隐藏它,是因为我有一个视频在“ DetailedVC”的最上方播放,所以我使用一个自定义按钮来弹出到收藏夹视图。我还隐藏了状态栏(类似于YouTube),但仍处于隐藏状态。
DetailedVC是常规视图控制器,并且不包含表视图或集合视图,因此我对为什么它让我向下滑动以及为什么导航栏不会保持隐藏状态感到困惑?
收集视图单元格,将DetailVC推入:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let detailVC = DetailController()
navigationController?.pushViewController(detailVC, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
详细的VC:
class DetailController: UIViewController {
let customButton: UIButton = {
let button = UIButton(type: .system)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("< Back", for: .normal)
button.setTitleColor(UIColor.orange, for: .normal)
button.addTarget(self, action: #selector(handleCustomButton), for: .touchUpInside)
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.isStatusBarHidden = true
// I tried all of these individually and cumulatively and the nav still shows when I swipe down
navigationController?.isNavigationBarHidden = true
navigationController?.navigationBar.isHidden = true
navigationController?.setNavigationBarHidden(true, animated: false)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIApplication.shared.isStatusBarHidden = false
}
@objc fileprivate func handleCustomButton()
navigationController?.popViewController(animated: true)
}
@objc fileprivate func configureButtonAnchors()
//customButton.leftAnchor...
}
Run Code Online (Sandbox Code Playgroud)
我不确定为什么为什么当我在DetailVC内向下滑动时,导航栏未被隐藏,但是我移动了代码以将其隐藏起来,viewDidLayoutSubviews而现在仍然保持隐藏状态。
为了解决我使用的问题navigationController?.setNavigationBarHidden(true, animated: false)并将其设置在里面viewWillLayoutSubviews:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// this one worked the best
navigationController?.setNavigationBarHidden(true, animated: false)
}
Run Code Online (Sandbox Code Playgroud)
并对其进行设置,使其可以显示在先前的vc内部(即集合视图):
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: false)
}
Run Code Online (Sandbox Code Playgroud)
我说效果最好,因为我分别尝试了全部3个,而这3个navigationController?.navigationBar.isHidden = true都是越野车。由于某种原因,即使viewDidLayoutSubviews导航栏没有出现,它也会使DetailedVC变得异常混乱。
而navigationController?.isNavigationBarHidden = true在DetailedVC里面工作过,导航栏呆隐藏的,现场没有混蛋,但是当我把它设置为false viewWillDisappear,这样的导航栏会显示父VC里面(集合视图)的导航栏没有出现在那里。
| 归档时间: |
|
| 查看次数: |
843 次 |
| 最近记录: |