【发布时间】:2018-03-09 00:22:21
【问题描述】:
一切都以编程方式发生。没有 Storyboard 和集合视图的 vc 和详细的 vc 都在 TabBarController 内。
我正在使用集合视图,当我点击didSelectItem 中的一个单元格时,我会按下详细视图控制器。在DetailedVC 中,我隐藏了导航控制器。我在viewDidLoad 和viewWillAppear 中分别和累积地调用了以下内容,以尝试将其隐藏:
navigationController?.isNavigationBarHidden = true
navigationController?.navigationBar.isHidden = true
navigationController?.setNavigationBarHidden(true, animated: false)
当场景首次出现时,导航栏是隐藏的。问题是当我在DetailedVC 上向下滑动时,导航栏从屏幕顶部向下滑动并不会消失。我是误滑下来才发现的。
我按下导航栏的后退按钮,即使它应该被隐藏,它也能正常工作。我隐藏它的原因是因为我有一个在DetailedVC 顶部播放的视频,所以我使用自定义按钮弹回集合视图。我还隐藏了状态栏(类似于 YouTube),但它仍然隐藏。
DetailedVC 是一个常规视图控制器,它不包含表格视图或集合视图,所以我很困惑为什么它让我向下滑动以及为什么导航栏不会保持隐藏?
推送DetailedVC的集合视图单元:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let detailVC = DetailController()
navigationController?.pushViewController(detailVC, animated: true)
}
详细的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...
}
【问题讨论】:
-
是否有导航控制器作为父 DetailController
-
@HarshalBhavsar 是的。集合视图使用 didSelectItem 中的导航控制器推动它
-
所以集合视图被嵌入到导航控制器中
-
@HarshalBhavsar 这是它能够使用 navigationController?.pushViewController 的唯一方法...如果集合视图不在导航控制器中,那将如何工作?
-
好的,所以在推送之前尝试隐藏导航栏。在 didSelectItem 中
标签: ios swift uiviewcontroller uinavigationcontroller uinavigationbar