I’ve an iOS app that makes use of UISplitViewController
as its root view controller. The “major” view of the break up view controller (the narrower one on the left) is a navigation controller. Oddly, the secure space utilized to the “secondary” view (the one taking over many of the display screen) contains that of the navigation bar within the major view.
If I then embed a navigation controller in a customized right-side break up view, its navigation bar will get pushed down by that very same secure space.
See this screenshot of a take a look at app on iPad:
The “Root View Controller” textual content on the appropriate is within the navigation bar of the first view controller. The blue view on the prime within the center is displaying the secure space – its prime is pinned to the highest edge and its backside is pinned to the highest secure space.
The grey area on the appropriate is a baby view controller that comprises a navigation controller. “Navigation Bar” there may be the navigation merchandise’s title within the root view controller of that navigation controller.
How do I cease this further secure space conduct of UISplitViewController
?
UpdateUINavigationController, and it is that navigation bar that is pushing all the things down. That is documented within the UISplitViewController
docs.
Here is the code for the “secondary” view controller space on this take a look at app:
class ViewController: UIViewController {
override func viewDidLoad() {
tremendous.viewDidLoad()
let safeAreaView = UIView()
safeAreaView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(safeAreaView)
safeAreaView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
safeAreaView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
safeAreaView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
safeAreaView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
safeAreaView.backgroundColor = .blue
let container = NavContainerViewController(nibName: nil, bundle: nil)
self.addChild(container)
self.view.addSubview(container.view)
container.didMove(toParent: self)
container.view.translatesAutoresizingMaskIntoConstraints = false
container.view.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
container.view.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
container.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
container.view.widthAnchor.constraint(equalTo: self.view.widthAnchor, multiplier: 0.33).isActive = true
}
}
class NavContainerViewController : UIViewController {
override func viewDidLoad() {
tremendous.viewDidLoad()
let youngster = NavChildController(nibName: nil, bundle: nil)
let nav = UINavigationController(rootViewController: youngster)
self.addChild(nav)
self.view.addSubview(nav.view)
nav.didMove(toParent: self)
nav.view.translatesAutoresizingMaskIntoConstraints = false
nav.view.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
nav.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
nav.view.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
nav.view.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
}
}
class NavChildController : UIViewController {
override func viewDidLoad() {
tremendous.viewDidLoad()
self.view.backgroundColor = .lightGray
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.textual content = "High"
self.view.addSubview(label)
label.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
label.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
self.navigationItem.title = "Navigation Bar"
}
}