SideMenu Functionality in swift 4 - ios

I am setting up the side menu by following SideMenu
When the app is loaded first the side menu controller is working fine (.menuslide)
but when I come back to the same controller from the side menu to the same view controller or any other controller or any other page it is not following (.menuslide)
I have tried by assigning the navigation
let menu = SideMenuNavigationController(rootViewController: YourViewController)
let rightMenuNavigationController = SideMenuNavigationController(rootViewController: YourViewController)
SideMenuManager.default.rightMenuNavigationController = rightMenuNavigationController
present(menu, animated: true, completion: nil)
through code and also
From the story board
I am navigating from every controller to side menu like this
let navigationController = storyboard!.instantiateViewController(withIdentifier: "sidemenunavigation") as! SideMenuNavigationController present(navigationController, animated: true, completion: nil)
for the first time after loading it is navigating properly (.menuslide)
but after navigating to other controller and get the side menu it is not following (.menuslide)

you may use the following RESideMenu for side menu quite easy to use
RESideMenu for side menu

please check this code is working fine for navigation another view controller for sidemenu
let storyBoard = UIStoryboard(name:"Main", bundle: nil)
if let conVC = storyBoard.instantiateViewController(withIdentifier: "RoutingAddViewController") as? RoutingAddViewController,
let navController = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController {
navController.pushViewController(conVC, animated: true)
}

Related

How to present a popup view in full screen

I've following view configuration
Tab bar -> Nav controller -> View: Click on a button -> segue to-> Another view: Click on a button -> Popup view.
This modal view is on a different storyboard.
I want to present this model view in full screen. I've tried this solution mentioned on Presenting modal in iOS 13 fullscreen but it doesn't work. I've also tried few other solutions but the popup view is not showing over full screen, status bar is visible at the top.
How do I present modal view in a full screen?
let storyboard = UIStoryboard(name: "Other", bundle: Bundle.main)
guard let popupVC = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as? PopUpViewController else {
print("PopUpViewController not found")
return
}
popupVC.modalPresentationStyle = .fullScreen
self.present(popupVC, animated: true, completion: nil)
You could try presenting with the navigation controller.
let storyboard = UIStoryboard(name: "Other", bundle: Bundle.main)
guard let popupVC = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as? PopUpViewController else {
print("PopUpViewController not found")
return
}
var navigationController = UINavigationController(rootViewController: popupVC)
navigationController.modalPresentationStyle = .fullScreen
self.present(navigationViewController, animated: true, completion: nil)
An alternative would be to use presentViewController but presentViewController will only present one viewController modally over the currently visible viewController whereas presenting with the navigationController will give the flexibility to push further components on top, providing a smoother navigation experience with go back to previous page kind of behaviour.
Maybe try creating the view controller this way:
let popOverVC = UIStoryboard(name: "yourBoard", bundle: nil).instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
self.addChild(popOverVC)
let lSs = UIScreen.main.bounds
popOverVC.view.frame = CGRect(x: 0, y: 0, width: lSs.width, height: lSs.height)
popOverVC.view.tag = tag
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParent: self)
Within the popup view controller class, add a method for animating its view in viewDidLoad.
Edit: I read your replies. The issue you are having is caused by not handling the status bar properly. Instead of trying to make this veiewcontroller fullscreen, simply hide the status bar
How do I hide the status bar in a Swift iOS app?
and bring it back when you want to see it again.

Issue while not using SlideMenuControllerSwift as the first viewcontroller

I am trying to use the third party SlideMenuControllerSwiftfor displaying a hamburger menu. I am able to display the hamburger menu properly when it is loaded in the very first viewcontroller that comes up. But in case I have a login screen for example and after the login screen, I navigate to another screen and when I try to show the slide menu in this screen, I am not able to do so properly.
In the example from github for SlideMenuControllerSwift, the required screens are loaded in the AppDelegate and called in the AppDelegate itself from didFinishLaunchingWithOptions. Following this idea, even if I call the method that is called in didFinishLaunchingWithOptions from the viewDidLoad of my screen of choice (where I want to display the hamburger menu), the hamburger menu is not showing up in that screen. I do get the logo of the hamburger menu displayed on top left but it is not clickable. Please help...:)
When user login try this.
SlideMenuOptions.contentViewDrag = true
SlideMenuOptions.leftViewWidth = self.view.frame.size.width * 0.75
let contentVC = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
let leftVC = self.storyboard?.instantiateViewController(withIdentifier: "LeftViewController") as! LeftViewController
let slideVC = SlideMenuController(mainViewController: contentVC, leftMenuViewController: leftVC)
slideVC.view.clipsToBounds = true
self.navigationController?.pushViewController(slideVC, animated: true)
Replace pushViewController with PresentViewController ,
let rootController = UIStoryboard.init(name:"Main", bundle: nil).instantiateViewController(withIdentifier:"HomeVC") as! HomeViewController
SlideMenuOptions.leftViewWidth = 280.0
SlideMenuOptions.contentViewScale = 1.0
let leftMenu = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "slidingMenuNavigationController") as! UINavigationController
let slideMenuController = SlideMenuController(mainViewController: rootController, leftMenuViewController: leftMenu)
present(slideMenuController, animated: true, completion: nil)

Tab Bar does not show on View Controller inside Navigation Controller

I'm running into this issue when I'm opening a new View Controller programmatically.
let controller = self.storyboard?.instantiateViewController(withIdentifier: "overViewScreen") as! OverviewViewController
controller.user = self.userObject
let navigationController = UINavigationController(rootViewController: controller)
self.present(navigationController, animated: true, completion: nil)
The structure of my project :
storyboard
On my storyboard the tab bar is shown onto the View Controller (with the table on the right), but when I run the app it looks like this :
enter image description here
I hope you guys can help me out!
Thank you.
You are presenting NavigationController without tab bar controller. You need to present TabBarController.
Give your TabBarController identifier and instantiate them just like you've done with controller
code from comment:
let tabVC = UIStoryboard(name: "NameOfYourStoryboard", bundle: Bundle.main).instantiateInitialViewController() as! UITabBarController
let navVc = tabVC.viewControllers.first as! UINavigationController
let vc = navVc.viewControllers.first as! OverviewViewController
vc.incorrectAuthorization = SettingsAuthorizationMethod.fingerprint
vc.user = self.userObject
present(navController, animated: true, completion: nil)
Ok, I managed to fix it like this :
let vc = self.storyboard?.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController
vc.user = self.userObject
let nvc = UINavigationController(rootViewController: vc)
self.present(nvc, animated: true, completion: nil)
I made a seperate controller class "TabBarController", and added a property "user" to this class. In my "OverViewController" I can get the property as follows :
let tabBar: TabBarController = tabBarController as! TabBarController
user = tabBar.user
Thanks for the help!

Swift - Present another view controller with its navigation bar

I have two ViewControllers -- one with storyboard and one without. Both of those view controllers have their own Navigation Bar at the top. Now when I use self.presentViewController(editorViewController, animated: true, completion: nil) my editorViewController comes up but without its Navigation bar.
Any ideas how to fix this?
I fixed the problem using the following code:
let editorViewController = IMGLYMainEditorViewController()
let navEditorViewController: UINavigationController = UINavigationController(rootViewController: editorViewController)
self.presentViewController(navEditorViewController, animated: true, completion: nil)
I just added the navEditorViewController as it made my navigation bar with its items to appear.
Try self.navigationController!.pushViewController(...)
Swift 5+
let destinationNavigationController = self.storyboard!.instantiateViewController(withIdentifier: "nav") as! UINavigationController
destinationNavigationController.modalPresentationStyle = .fullScreen
self.present(destinationNavigationController, animated: true, completion: nil)
Here your navigation bar replaces with new navigation bar.
So for everyone still curious about this problem, given that we already have existing UINavigationController other than the current one:
Swift 3
First, we need to find the UIViewController that we want to present:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let destinationViewController = storyboard.instantiateViewController(withIdentifier: "DestinationViewController") as! DestinationViewController
Next, we're doing the same thing for UINavigationController:
let destinationNavigationController = storyboard.instantiateViewController(withIdentifier: "DestinationNavigationController") as! UINavigationController
Then, we want to bring the DestinationViewController to the top of our destination UINavigationController stack:
destinationNavigationController.pushViewController(destinationViewController, animated: true)
Finally, just present destination UINavigationController:
self.present(destinationNavigationController, animated: true, completion: nil)

iOS Swift - Presenting View Controller sliding down while presenting new View Controller

I present a View Controller in the following fashion:
let vc: ChangeDateViewController = storyboard!.instantiateViewControllerWithIdentifier("changedate") as! ChangeDateViewController
let navigationController = UINavigationController(rootViewController: vc) //ensures that the top navigation bar remains in the new View Controller
self.presentViewController(navigationController, animated: true, completion: nil)
For some reason, the base presenting View Controller slides down while the new View Controller is sliding up. Although the presenting works, it does look glitchy because the sliding down reveals the black background behind the views. Is this a common occurrence, and is there anything I can do to prevent it?
Try this:
let storyboard1 = UIStoryboard(name: "Main", bundle: nil)
let conn = storyboard1.instantiateViewControllerWithIdentifier("changedate") as! LMAddaccountMainVC
self.presentViewController(conn, animated: true, completion: nil)
This might be helpful to solve you issue.

Resources