Closed jossiwolf closed 8 years ago
Through Storyboards, I don't believe it will work. You could however use Storyboards for your ViewControllers, and then you would only need to set the SideNav's left or right width programmatically.
You would use these lines:
sideNavigationViewController?.setLeftViewWidth(300, hidden: true, animated: false)
sideNavigationViewController?.setRightViewWidth(300, hidden: true, animated: false)
In order for those lines to work correctly, it would need to be done in the viewWillAppear method of your ViewController, or after the instantiation of the SideNav in the AppDelegate.
Here are two examples:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Get view controllers from storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = storyboard.instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController
let sideViewController = storyboard.instantiateViewControllerWithIdentifier("SideViewController") as! SideViewController
let sideNavigationViewController: SideNavigationViewController = SideNavigationViewController(mainViewController: mainViewController, leftViewController: sideViewController)
sideNavigationViewController.setLeftViewWidth(300, hidden: true, animated: false)
// Configure the window with the SideNavigationViewController as the root view controller
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = sideNavigationViewController
window?.makeKeyAndVisible()
return true
}
// or
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
sideNavigationViewController?.setLeftViewWidth(view.bounds.width - 88, hidden: true, animated: false)
}
The reason for placing it in the viewWillAppear, if you choose that route, is because of the race-condition which would occur when instantiating the views and placing them within the SideNav.init method. Basically, the SideNav, won't exist at that time.
Hope this works for you :)
If you have any further questions, please reopen or create a new issue. All the best :)
Thank you!
How can I set the width of a navigation drawer? I'm not creating it programatically, but via storyboards.