How can I implement hide on swipe programmatically? the reason why I don't want to use the Hide Bars on swipe option from the attributes menu is because I came across a problem. When enabled, the app will hide the navigation bar, as well as the toolbar if the user scrolls down the content view, and the bars will appear when the user swipes back up. I don't want this change to apply to all the navigation bars of the entire app. I want to be able to just hide one navigation bar. I did gave this an attempt, I set the hidesBarsOnSwipe property to true as shown in the code below
navigationController?.hideBarsOnSwipe = true but I came across other problems, I tried placing my code above the viewDidLoad method in the ViewControllers where this feature will be enabled and I set the property to false on the ones I don't want to this featured to be enabled.
My problem: I can't hide the navigation bar after navigating back to the view controller with the false property
I don't understand what I'm doing wrong, any suggestions?
Instead of putting your code in viewDidLoad(), put it in viewWillAppear() -- that ensures it's called every time your View Controller comes on screen, since with Navigation Controllers, the viewDidLoad() method isn't always called when view controllers are popped. Also make sure to explicitly mention the preffered setting for each view controller -- i.e. navigationController?.hideBarsOnSwipe in the viewWillAppear() of each of your View Controllers.
Hope this helps.
Swift 4
navigationController?.hidesBarsOnSwipe = false
Related
I have a navigation controller that pushes an UITabBarController. So, all my tab view controllers will share the same navigation bar. Not a problem so far because I setup the navigation item's content every time tabBarController(_:didSelect:) is called.
Let's say we have only 2 controllers in the tab bar and every controller will have an UISearchController. Being attached to the navigation item, this search controllers will be configured every time tabBarController(_:didSelect:) is called.
Every thing works and looks as required until now.
The problem is that when I tap the search bar from the first controller the keyboard appears and the search works, but when I tap the search bar from the second controller nothing happens.
[Being in the second tab]
I know that the UISearchBarDelegate's searchBarShouldBeginEditing(_:) is called, but if I try in that method to set searchController.isActive = true, then the app will crash with the following message: Attempt to present UISearchController on <FirstTabViewController> whose view is not in the window hierarchy.
Have you ever encountered this issue?
Do you set the definesPresentationContext property to true when you access the second view controller?
I'm a new Swift developer. I'm using Swift 4.2 and XCode 10.2.
I have a tab bar controller with 5 tab bar items. In the view controller for each tab bar item there is a button to show the balance in a different view controller (call it the Balance View Controller). I have a segue from each button to the Balance View Controller.
I am using interface builder, but will be happy to add code.
How can I put the main tab bar on the Balance View Controller so when the user is done viewing the balance, he can select another tab bar item and keep going? I rejected using a navigation controller because the back button will interfere with the uniform view at the top of every screen and I don't want to adjust it.
I could not find any SO questions that address this issue. And all the other web resources I found are very basic on how to implement tab bars. Any help would be appreciated.
Another approach:
Load Balance View Controller as a Child ViewController, and display its view on top of the current view. This will leave the tab bar alone, allowing users to navigate to another tab.
Balance View Controller sounds like it's just an information display. If so, you can add a tap gesture to remove it from the current view on a simple tap.
If Balance View Controller is interactive, you can add a button to remove it from the current view.
Since you say you have a button in each tab's VC to show the Balance View Controller, then you probably also want to remove it from the current view when another tab is selected.
I rejected using a navigation controller because the back button will interfere with the uniform view at the top of every screen and I don't want to adjust it.
The best way to achieve this is with a UINavigationController what we can do about the Top navigation bar and the darn back button is we can hide the whole thing by
// Add this to your viewcontroller
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = true
}
And going further if you want to you can disable the animations for the view controller
hope this helps
If I've got 6 screens total and I'm wanting to add a navigation controller between my last two scenes so my final screen has a nav bar/ navigation through a navigation controller is there an easy way to do that?
I've tried embedding a nav controller into my first scene and switching my segues to "show" and setting the navigationbar.isHidden to true in appear and then on my last screen trying to set it to false in viewdidappear and then to true again in viewdiddissapear.
First of all it didn't work, (I just need to tinker with it probably), but secondly it seems like a lot of "work" just to get navigation between two screens.
Do you have to have navigation throughout your entire project to get navigation between two specific screens? What's the best way to do this?
If you have a storyboard, you should be able to select the second-last screen and use the Editor->Embed in->Navigation controller menu item.
In the viewController that you want to hide the navBar add the following in viewDidLoad
self.navigationController!.isNavigationBarHidden = true
I have an app that has a toolbar, but I don't want the bar at the top, in order to free more viewing space. Therefore I have decided not to use a navigation controller. I'd like to add a back button to the toolbar. How would I go about this?
Adding the button is easy enough, and setting the action to performSegueWithIdentifier is all fine, but what happens is that the previous view just gets loaded again, rather than show it as it was, like a true back button. So if I tap on the 10th row on a tableView and go to a new page, when I press the back button it loads the view from the top again, instead of showing it as where I scrolled down to last.
Even though you don't want a UINavigationBar, you do want a UINavigationController in this case, because it manages the 'back stack' exactly the way you want it. Just hide its navigation bar by setting its navigationBarHidden property to true (in the Storyboard or in the viewDidLoad function of the root view controller).
You can then use navigationController.popViewController(true) as normal, in response to the user clicking your custom back button.
I am having difficulty figuring out how to set up my UINavigationController to get the result I want. Most succinctly, I want to mimic the navigation of the app BriefMe.
Specifically, I want:
a main view (v#1) that segues to a new view controller (v#2) with an embedded UIWebView
to permanently hide/disable the navigation bar and toolbar on v#1, but I do want a toolbar on v#2 (ideally which shows/hides on swipe -- I figure this can be solved with a UIGestureRecognizer if not through the NavController's hide on swipe/tap property)
v#2 to segue back to v#1 on a swipe from the left edge of the screen, just like the default NavController behavior, shown here.
I've run into two problems with my attempt to set this up:
I can't permanently hide the navigation/toolbar on v#1 while leaving v#1+#2 embedded in a NavController. Without the NavController, I don't retain the swipe-to-segue functionality when v#2 is at the top of the stack
Allowing the WebView to scroll disables/'intercepts' the swipe-to-segue functionality. My only thought is to disable interaction with the WebView, place the WebView in a ScrollView, and allow only vertical scrolling on the ScrollView. Will this allow the swipe-to-segue to work?
If I understand your questions correctly:
We’re still popping a controller from the stack during the transition. We just add the navigation bar as a subview of the controller’s view at the top of the stack and then set up the back event manually.
We ended up using a version of the answer specified here. We added an extra invisible thin column overlaying the left side of the webview because some webviews were still giving us trouble.
Hope that helps!