Reputation: 406
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.
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:
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.
Upvotes: 1
Views: 1756
Reputation: 2077
You can archive this type of behaviour using embedded view controller. See my view hierarchy in image : You can embedded navigation controller as subview.
In Last view you have to create view like navigation bar, and you have to write code for pop view controller.
Here is the code :
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
class MainViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
class SubViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.navigationController?.interactivePopGestureRecognizer?.delegate = nil
}
@IBAction func onClickBack(_ sender: UIButton) {
self.navigationController?.popViewController(animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Actual Result :
Upvotes: 2