UITabBarController with Hamburger menu/ Left sliding menu - ios

I have an app with UITabBarController set as root controller. I need to have a hamburger menu no matter on which tab the user is. The question is - how to structure the app so that I don't have to repeat the hamburger menu code for every view controller - is there a way to do that? Only the gestures handling for opening and hiding the menu are around 100 lines of code. After a table view is added for the items in the hamburger menu I imagine it's going to be twice as that. Thanks in advance for the suggestions.

I ended up using another View Controller as a parent view controller and adding the UITabBarController as a child view controller to it. Then I added the Hamburger menu to the parent view controller and set screenEdgePanGesture.cancelsTouchesInView = false for the gesture that opens the menu. On start of the gesture (state .began) I am setting the isHidden property of the menu view to false and call view.bringSubviewToFront(self.menuView) to have the menu over the views in the current tab.

Related

What is the standard method for implementing navigation menus in swift?

I'm trying to create navigation through the use of a menu in my app, but I'm not sure how it should be done. I currently have a system set out like this:
ContainerViewController
|
+---CenterNavigationController
|
+---ViewControllerA [i.e. the root view controller which will be changed]
|
+---MenuViewController [pushed to navigation stack on btn press]
and when a item in the menu is pressed to load another view controller, MenuViewController calls a delegate method in the ContainerViewController which replaces the NavigationController with a new one with a different root
let newVC = ViewControllerB()
CenterNavigationController = UINavigationController(rootViewController: newVC)
However this looks janky, both in the code and in the aesthetics of the app.
I'm not sure how to do this properly. I'm wanting the menu to be overlayed onto the current view, and have the ability to click 'back' in the menu to go back to what was showing on screen before the menuVC was loaded. How can I do this?
You do all correct. If navigation animation isn't good, then improve it. You can show menu animated from the left side and reload CenterNavigationController without animation. As for transparence, then just change the color of the main view of the menu view controller to semitransparent. The first subview that contains all menu items should be non-transparent and have lower width and sticked to the left side. That's it.
I think you should not push menu view controller into the navigation stack. Just load it right into the UINavigationView controller.
You can check loadViewController (line 251) method here https://gitlab.com/seriyvolk83/SwiftEx/blob/master/Source/UIExtensions.swift
It loads view controller into another view controller in a given bounds. To remove it later (close menu) you can use remove() (see line 321)
Hamburger menu is antipattern on iOS, I suggest using UITabBarController. If someone is holding a gun to your head and forcing you to put a hamburger menu in your app then use something like this: https://github.com/jonkykong/SideMenu

Add Main Tab Bar to Other 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

Dragging Bar Button Item to Navigation Controller fails

I am following a tutorial on Udemy about Navigation Controllers.
The instructions are to drag a Navigation Controller onto the storyboard, and then drag and drop a Bar Button Item on the right of its navigation bar to segue to another view controller.
However, when I drag the Bar Button Item to its would-be position on the navigation bar, no drop-zone gets highlighted, and the button gets added to a random tab at the bottom of the screen.
I have tried finding references to this problem but all solutions are programmatic and given the wysiwyg nature of iOS development I would like to solve it through XCode UI.
Is there some setup I must change or is this an XCode 7 discrepancy?
Try to add a ViewController and then in Editor -> Embed in -> NavigationController. Then it should work.
I have solved my problem by dragging the Bar Button Item into the Document Outline, below Root View Controller.
This automatically creates Left Bar Button Items and Right Bar Button Items, which gives you an opportunity to drag the Item in the section of the controller you like.

Tab Bar Controller - Show a view controller that is not one of the tabs

I wonder if this is possible. The design for this app I am working on is as below:
Two sliding views sit one on top of the other. The bottom view is a 'Settings' view. The top view is a tab bar view. We are using ECSlidingViewController for the sliding.
When the app is opened for the first time, the tab bar view shows with first tab selected.
When they tap on the hamburger menu or slide right, the bottom, settings view slides into view.
When they tap on an item in the settings view, like the About item, the corresponding view should be displayed inside the top tab bar view with none of the tabs shown as selected.
I think I am going to have to convince my team to not display the settings items inside of the tab bar, it seems just too twisted. But just wanted to know if anyone else has done anything like this and if it is possible to do it without introducing too much complication in the code.
I've done something with the same design with a menu that slides from the left and over the tab bars. I ended up putting a View Controller on top of everything else
Something like
[self presentViewController:AboutViewController Animated:YES];
Just make sure that you either put that view controller in a UINavigationController or something with a dismissViewController for users to return to your main page.

Tab bar disappears when trying to go back from new view

I am very new to Xcode and have encountered an issue with my app. I am trying to create a tab bar app. On one of the tabs I have a button that brings the user to a different ViewController. I want to have it so the user can select a button that would return them to the tab that had the button. I tried to set up an action from the button to the previous view (the tabbed screen), however the tab bar disappears. I hope this is makes sense.
Here is a link to a screenshot...
Easiest way to do this is to place a UINavigationController as the root view controller of the TabBarController. You can do this in storyboard by simply ctrl+dragging from the tabbar controller to the navigation controller and adding it as a relationship.
Here's an example using storyboards:
The next step is to set the third controller (in this case the table view controller) to your player view controller class.
Then, you can use the default back button and animation that comes with the navigation controller. If you prefer to hide the navigation bar at the top of the screen, then you can use your custom back button to call
[self.navigationController popViewControllerAnimated:YES];
You can also choose custom animations / segues, etc. but using a navigation controller to help you navigate screens is probably the simplest approach.

Resources