I am using following layout design
but when i click on central circular button it's cover the whole screen ... i want to make tabbar visible on every click ...
I try to open ViewController as a sub view with following code
guard let StoreVC = self.storyboard?.instantiateViewController(withIdentifier: "StoreVC") else { return }
StoreVC.view.frame = self.view.bounds
self.addChild(StoreVC)
self.view.addSubview(StoreVC.view)
StoreVC.didMove(toParent: self)
but its cover the entire screen including tabbar ..
i try following code but still does't work as expected ...
guard let StoreVC = self.storyboard?.instantiateViewController(withIdentifier: "StoreVC") else { return }
self.definesPresentationContext = true
StoreVC.modalPresentationStyle = .overCurrentContext
self.present(StoreVC,animated: true, completion: nil)
Embedding it in a navigation controller also does't work ...
This circular button is not the part of Tabbar but i want it to act like a tabBarItem ...
if i make it part of tabbar it upper part not click able ...
just like explain in this question TabBarController adding custom button not clickable issue
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a lot of pages in my project so I am using multiple storyboaords. After my login page I want to go to a tab bar controller which has five pages. So my tab bar controller is in it's own storyboard. The storyboard name is HomePage and the tab bar identifier is HomePageVC.
So the code I'm using to call it from the login page (after logging in) is:
let storyboard = UIStoryboard(name: "HomePage", bundle: nil)
let secondVC = storyboard.instantiateViewController(identifier: "HomePageVC")
self.navigationController?.pushViewController(secondVC, animated: true)
The HomePage storyboard is then setup this way
[![enter image description here][1]][1]
Each of the five tabs lead to a different view controller in a different storyboard (I'm using storyboard references for this). Now I'm having three problems:
When I use this method to show the tab bar and the next view controller somehow there are two navigation controllers. So basically it's a view controller connected to a nav bar controller (and the nav bar controller is set as the initial view controller). The problem is the previous view controllers nav bar is being pushed to the next view controllers nav bar. Causing a double Mac bar. I want to remove the top nav bar and have the text of the below one.
The second problem I'm having is the tab bar doesn't actually show up properly it is just a gray bar. However, I think the buttons are still there as when I click on a section of the tab bar where a button should be, it goes to that view controller.
The last problem is that the images I put in for the tab bar buttons are too big. How do you resize them to be the proper size. I'm not sure if this is what is causing the second problem but it could be. So how could I solve these problems.
Note for the future: You should only ask one question at a time.
For question 1 - double navigation bar.
In your Login view controller, you can do this:
class LogInViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// show the navigation bar
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
#IBAction func loginTapped(_ sender: Any) {
// hide the navigation bar
self.navigationController?.setNavigationBarHidden(true, animated: false)
let storyboard = UIStoryboard(name: "HomePage", bundle: nil)
let secondVC = storyboard.instantiateViewController(identifier: "HomePageVC")
self.navigationController?.pushViewController(secondVC, animated: true)
}
}
Question 2 - tab bar icons not showing.
Embedding a Tab Bar Controller in a Navigation Controller is generally considered bad practice, as navigation can be confusing for the user. However, I'm not Apple, and if it fits your design and the navigation remains intuitive...
I just gave it a try, and no, the tab bar button icons (and titles) don't show up. Not entirely sure why... but here is a way to do it.
First, delete all your current tab bar controller connections. So your "HomePage" Storyboard will simply have a Tab Bar Controller (with Storyboard ID of "HomePageVC").
Next, add a UITabBarController subclass to your project, and assign it to the "HomePageVC" tab bar controller. It will look something like this:
class MyTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
var sb = UIStoryboard(name: "Settings", bundle: nil)
guard let tab1VC = sb.instantiateInitialViewController() else {
fatalError("Could not load Settings VC!")
}
guard let tab1Icon = UIImage(named: "settignsTabIcon") else {
fatalError("Could not load settignsTabIcon image!")
}
tab1VC.tabBarItem = UITabBarItem(title: "Settings", image: tab1Icon, selectedImage: tab1Icon)
sb = UIStoryboard(name: "Communication", bundle: nil)
guard let tab2VC = sb.instantiateInitialViewController() else {
fatalError("Could not load Communication VC!")
}
guard let tab2Icon = UIImage(named: "communicationTabIcon") else {
fatalError("Could not load communicationTabIcon image!")
}
tab2VC.tabBarItem = UITabBarItem(title: "Comunication", image: tab2Icon, selectedImage: tab2Icon)
// etc for your other 3 tabs
let viewControllerList = [ tab1VC, tab2VC ]
viewControllers = viewControllerList
}
}
As to question 3 - tab icon size... you can probably find that with an easy search... if you can't, come back and ask that as a new post.
I'm using SWRevealController to have a side menu. In my app ,it also have UITabBarcontroller.
My connection format is as SWRevealViewController--->UItabbarController--->NavigationController--->UITabbaritemPage-->Another vc
PLEASE CLICK ON THE IMAGE TO SEE IN CORRECT ORIENTATION
The above show is the layout I'm using.I want to have that burger button (menu button) in almost all vc that are showing from and in tabbarcontroller. Currently I'm getting the side menu when tapping on the Button (The image showed in right side as spereate).On choosing a menu, it shows the desired vc but,the bottom tab bar is not there. I want to have the bottom tabbar in entire pages also in pages from the side menu.
How can I acheive this? Please help me.
The code I'm using in didSelectRowAtIndexPath is:
if indexPath.row == 1{
let destinationVc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
let newFrontVc = UINavigationController.init(rootViewController:destinationVc!)
revealViewController.pushFrontViewController(newFrontVc, animated: true)
}
I think you don't actually need to push a view controller if using tab bar controller.
let tabBarController = self.storyboard?.instantiateViewController(withIdentifier: "TabBarController")
tabBarController.selectedIndex = 1
revealViewController.pushFrontViewController(tabBarController, animated: true)
You would have to set the identifier of the tab bar controller to be TabBarController in Main.storyboard for this to work.
I also had the same layout like you only few view controllers has been added to the tabbar and it will show the tab bar in all view controllers
SWRevealViewController with TabBarController using XIB in Swift 4
let objSideBarVC = SideBarVC(nibName: "SideBarVC", bundle: nil)
let navSidebar = UINavigationController(rootViewController: objSideBarVC)
navSidebar.navigationBar.isHidden = true
let objDashboardVC = DashboardVC(nibName: "DashboardVC", bundle: nil)
let navDashboard = UINavigationController(rootViewController: objDashboardVC)
navDashboard.navigationBar.isHidden = true
let mainRevealController = SWRevealViewController.init(rearViewController: navSidebar,frontViewController: navDashboard)
AppDelegate().window?.rootViewController = mainRevealController
mainRevealController.pushFrontViewController(TabBarController, animated: true)
From the iphone system APP “Contacts”, in the “All Contacts” GUI and click “Add”, it will segue to “New Contact” GUI. Then from the “New Contact” GUI and add “new” item then click “Done”, it will seuge to the contact detail GUI(screenshot image 3). The issue is that: I used “Show(push)” to segue to image 3 from “Done” button,
but the NavagationItem in the left corner displayed as “ back to New Contact “ rather than “back to All Contact”.
I attached the screenshot to describe the issue as bleow:
screenshot
I tried two ways:
way 1: pop the vc which matches the image2. The isssue is that New Record page will jump to image1 first, then jump to image3.
if let nav = self.parentViewController as? UINavigationController {
if let vc0 = nav.childViewControllers.last as? AddRecordTableViewController {
nav.popViewControllerAnimated(true)
}
}
performSegueWithIdentifier(Constants.SegueAddRecordVCToViewRecordVC, sender: nil)
way 2:
used the removeFromParentViewController to discard the vc matches image2. The issue is that the Navagation bar button in the left corner still displayed as “
if let nav = self.parentViewController as? UINavigationController {
if let vc0 = nav.childViewControllers.last as? AddRecordTableViewController {
vc0.removeFromParentViewController()
}
}
performSegueWithIdentifier(Constants.SegueAddRecordVCToViewRecordVC, sender: nil)
Why dont you try using self.dismissViewControllerAnimated(true, completion: {}); when "Done" is pressed.
I'm currently writing an app where we are launching a walkthrough the first time the user opens the app. At the end of it, we require the user to fill in a few details, and to do so I would like him to press a button to get redirected to the settings page.
The thing is, this page is one level down the navigation controller (from the landing page). As it stands, I can correctly instantiate the landing page, but the redirection to the settings page never happens.
let mainView = self.storyboard?.instantiateViewControllerWithIdentifier("NavCtrl")
self.presentViewController(mainView!, animated: false, completion: nil)
// the above works correctly and sends us to the landing screen
// (rootView of the navigation controller)
// the following lines never have any effect though
let settingsView = self.storyboard?.instantiateViewControllerWithIdentifier("Settings View")
self.navigationController?.pushViewController(settingsView!, animated: false)
I think it's because I'm trying to call .pushViewController before the storyboard had time to instiate either the first or second view.
So I have a few questions:
Is there a way to, indeed, instantiate a view and then navigate to another one right after it has been instantiated ? (this in order to keep the navigation stack and maintain accurate nav bar behaviour)
If there isn't, would it be possible to programmatically populate the navigation stack so that I would only need to instantiate the settings view ? This in order to still have the back button in the nav bar that would send to the landing screen ?
Thanks in advance guys
Ok thanks to #Leonardo for showing me the correct direction !
I solved the issue by doing the following in appDelegate:
/*
* Override window root view and set it to a newly initialized one
* view: StoryboardID of view to display
* navigateTo: if true, set the root view to NavCtrl and then navigate to the desired view
*/
func setWindowViewTo(view: String, navigateTo: Bool) {
//initalize storyboard & window programmatically
window = UIWindow.init(frame: UIScreen.mainScreen().bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
//if true, navigate from landing page to specified view through navigationController
if(navigateTo) {
//instantiate the navigation controller
let navCtrl = storyboard.instantiateViewControllerWithIdentifier("NavCtrl") as! UINavigationController
//instantiate the landing page & the page we wish to navigate to
let landingView = storyboard.instantiateViewControllerWithIdentifier("Main View")
let vc = storyboard.instantiateViewControllerWithIdentifier(view)
//manually set the navigation stack to landing view + view to navigate to
navCtrl.setViewControllers([landingView, vc], animated: false)
//replace the rootViewController to the navigation controller
window!.rootViewController = navCtrl
//make it work
window!.makeKeyAndVisible()
} else {
window!.rootViewController = storyboard.instantiateViewControllerWithIdentifier(view)
window!.makeKeyAndVisible()
}
}
The important step was to indeed force downcast as! UINavigationController when instantiating the NavigationController with the storyboard.instantiateViewControllerWithIdentifier() method.
Then it's just a case to correctly instantiate the views of the navigation stack you want, and finally calling navCtrl.setViewControllers([view1, view2], animate: false).
Thanks all for your help !
You can use the - setViewControllers:animated: method to set the navigation stack of a UINavigationController
Here's the reference
But I don't think that's your problem, if I undestood your code correctly, it should be
//This is the navigation controller
if let mainView = self.storyboard?.instantiateViewControllerWithIdentifier("NavCtrl"){
//Nav being modally presented
self.presentViewController(mainView, animated: false, completion: nil)
// Instantiate the settings view
if let settingsView = self.storyboard?.instantiateViewControllerWithIdentifier("Settings View"){
//Push it to the navigation controller presented
mainView.pushViewController(settingsView, animated: false)
}
else{
//Can't Instantiate, deal with error
}
}
else{
//Can't Instantiate, deal with error
}
I'm using Swift 2 and xcode 7.1.1.
My app is a tabbar + navigationbar based application.
What I'd like to do:
From my first viewcontroller (CollectionVC) I have a collectionview of images(tabbar at bottom and navbar at top). When you select an image, I transition programmatically to a modalviewcontroller (ImageZoomVC) that allows them to zoom on the image (no tabbar or navbar). From the ImageZoomVC I want to transition programmatically to the UserProfileVC. The UserProfileVC should have the tabbar and navbar like the first view. The navbars back button should also take us back to the ImageZoomVC.
This workflow is similar to facebook. When you select an image, you go to a black screen with just that image and some more info. You can click on anyone tagged in the image and it will push their profile onscreen with the tabbar and navbar back in place.
The Problem:
Once in the ImageZoomVC, I can't transition to the UserProfileVC without losing the tabbar and navbar. I've been able to add a navbar programmatically but there is no back button, and setting a back button hasn't worked. Also, there is no tabbar.
Code:
From my CollectionVC, I transition to the ImageZoomVC from my collectioncell like this:
#IBAction func PhotoButtonPressed(sender: UIButton) {
let imageZoom = ImageZoomVC()
imageZoom.showFrom(self.parentView!)
}
Here is the showFrom function that presents the ImageZoomVC modally. This code is inside the ImageZoomVC:
public func showFrom(viewController: UIViewController) {
//Some stuff here, edited for length
viewController.presentViewController(self, animated: false) {
UIView.animateWithDuration(ImageZoomVC.TransitionAnimationDuration,
delay: 0,
options: [.BeginFromCurrentState, .CurveEaseInOut],
animations: {
[weak self] in
self?.collectionView.alpha = 1
self?.collectionView.transform = CGAffineTransformIdentity
},
completion: {
[weak self] finished in
self?.view.userInteractionEnabled = finished
}
)
}
}
This is the code I'm attempting to use to transition to the UserProfileVC with navbar and tabbar. This doesn't work. It will present the VC, but there is no tabbar or back button.
func userSelected (sender: UIButton) {
let vc = self.presentingViewController?.storyboard?.instantiateViewControllerWithIdentifier("User Profile") as! UserProfileVC
let newNav = UINavigationController(rootViewController: vc)
newNav.navigationBar.barTintColor = UIColor().specialPurple()
newNav.navigationBar.translucent = false
self.presentViewController(newNav, animated: true, completion: nil)
}
A couple notes: The ImageZoomVC doesn't exist in storyboard. It is called and instantiated programmatically.
The ImageZoomVC is based off Agrume from Github found here:
https://github.com/JanGorman/Agrume
I'd like to push the UserProfileVC like facebook does. This current code presents it from the bottom. The code pushViewController is not recognized here in xCode.
Let me know what you think. All thoughts are welcome. Thanks.