I would push a UINavigationController in the same way Favorite/Bookmarks Folders are presented in iOS Safari:
I already tried using a single UINavigationController, setting navigationController?.setNavigationBarHidden(true, animated: false)
in viewWillAppear
for the first view, but I can't get the desidered behavior: I would have the navigationbar to slide in when child viewControllers are pushed and to slide out when returning to the rootViewController.
Any suggestion? I'm using Swift 4.0.3, developing target iOS 11, thanks in advance.
Edit
I tried to achieve the wanted behavior by nesting two UINavigationControllers:
mainNavController: UINavigationController // with hidden NavigationBar
- firstFavoritePage: UIViewController // as rootViewController
- wrapper: UIViewController // a containerViewController
- nestedNavController: UINavigationController
- blankPageWithTitleAll: UIViewController // as rootViewController
- folderPage: UIViewController
I added a wrapper container ViewController since two UINavigationControllers are merged while directly nested (to have UISplitViewController working as expected) and I added a blank page in the inner NavigationController with the title "All" to get the "< All" back button to animate correctly on pushes (a custom back button fades out, a real back button not).
In Swift:
let wrapper = UIViewController()
let blankPageWithTitleAll = UIViewController()
let folderPage = UIViewController()
let nestedNavController = UINavigationController(rootViewController: blankPageWithTitleAll
wrapper.addChildViewController(nestedNavController)
wrapper.view.addSubview(nestedNavController.view)
nestedNavController.view.anchorToSuperview(wrapper.view)
nestedNavController.didMove(toParentViewController: wrapper)
nestedNavController.pushViewController(folderPage, animated: false)
blankPageWithTitleAll.navigationItem.title = "All"
firstFavoritePage.show(wrapper, sender: self)
Now the presenting animation works as expected, but to dismiss everything, if the active ViewController is the second or first controller of the nestedNavController navigation stack, I should:
- prevent the nestedNavController interactive pop transition;
- prevent the nestedNavController back button pop transition;
- add a custom action when the "< All" back button is pressed to pop the mainNavController instead of the nestedNavController;
- [probably the most difficult thing to do] mirror the pop UIPercentDrivenInteractiveTransition (the edge swipe to go back interactive animation) of the nestedNavController to the mainNavController.
I don't even know if I can get or set percentage values for that animated transition (I don't think it could be possible.. but I'll try to figure out if it is).
Any other way (possibly simpler) to have this working correctly is highly appreciated, thanks.