Introduction
I'm creating a simple app in with the RootViewController
is embedded in a UINavigationController
. I have a UIView
subclass "landscapeView" with a UICollectionView
in it that fills the view. "landscapeView" is hidden in portrait and displayed in landscape device orientation.
Issue
When the device is rotated to a landscape orientation I hide the navigationBar and the portrait table view "rootTableView", while showing the "landscapeView". However, the navigationBar appears when I tap the screen in landscape orientation. I can't figure out how to disable this tap to show thing. (I have `navigationController?.hidesBarsOnTap = false, its setup to default in storyboard).
Clarification: hiding the navigation bar works perfectly depending on device orientation.
Question
How can I prevent the navigationBar from appearing when the screen is tapped in landscape orientation?
Code
viewWillTransition()
in the "RootViewController"private let landscapeView = LandscapeView(frame: .zero) private let rootTableView = UITableView(frame: .zero, style: .grouped) override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) var isLandscape = true switch UIDevice.current.orientation { case .landscapeLeft: navigationController?.navigationItem.searchController?.accessibilityElementsHidden = true isLandscape = true case .landscapeRight: navigationController?.navigationItem.searchController?.accessibilityElementsHidden = true isLandscape = true case .portrait, .portraitUpsideDown, .faceUp, .faceDown, .unknown: isLandscape = false navigationController?.navigationItem.searchController?.accessibilityElementsHidden = false default: break } if isLandscape { navigationController?.setNavigationBarHidden(true, animated: false) self.landscapeView.isHidden = false // This simply tells the "landscapeView" to layoutSubviews() and reloadData() for the collectionView within. landscapeViewDelegate?.landscapeViewWillAppear(inDarkMode: inDarkMode) } UIView.animate(withDuration: 0.6, delay: 0, options: .layoutSubviews, animations: { // This is a tableView displayed in portrait mode. self.rootTableView.alpha = isLandscape ? 0 : 1 self.landscapeView.alpha = isLandscape ? 1 : 0 }) { (success) in if isLandscape == false { self.landscapeView.isHidden = true self.navigationController?.setNavigationBarHidden(false, animated: true) } return } }
Thanks for reading.
UICollectionView
within the "landscapeView", however the navigationController still appears when I tap the landscapeView. – theoadahl