The main navigation for my iOS 8 app is a tab bar with 3 tabs. I also have a login screen that is a UIViewController that should not have tabs at the bottom. I only ever access the login screen programmatically from the normal flow if I detect that a user is either not logged in, or has chosen to log out. I'm not sure how to remove the tabs from the screen when I show the login screen with the following code:
let loginView = self.storyboard?.instantiateViewControllerWithIdentifer("Login") as UIViewController
self.presentViewController(loginView, animate: true, completion: nil)
I have tried setting the tabBar.hidden property to true with no result. I have also tried modifying the storyboard to set "Bottom Bar" to "None" and have checked "Hide Bottom Bar on Push".
Maybe the login screen's behavior is different from the main screen. So you might want to create another ViewController for the Login screen.
I have tried setting the tabBar.hidden property to true with no result.
Does it finish to load the tab bar? Call hidden=YES after viewDidLoad of your loginView.
EDIT
After you call self.presentViewController(loginView, ...), the UITabBarController's view will be removed from UIWindow, and the loginView's view will be inserted to UIWindow's subview. So the tab bar is invisible now.
You can use View Debugging feature of XCode6 to understand the view hierarchy. You can use UIViewController's recursiveDescription() method too.
/* UIViewExtension.h */
#interface UIView(MyExtension)
- (NSString*)recursiveDescription; //This is hidden API so need the declaration.
#end
/* YourViewController.swift */
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
println(self.tabBarController?.view.superview?.recursiveDescription())
// Here, the view of tabBarController is subview of UIWindow.
}
#IBAction func testButtonPressed(sender: UIButton) {
self.presentViewController(viewController, animated: true) { () -> Void in
println(self.tabBarController?.view.superview?.recursiveDescription())
println(loginView.view.superview?.superview?.recursiveDescription())
//Now, TabBarController's view is not subView of UIWindow.
}
}
Related
I have a modal view controller A presented at the top of the view controllers hierarchy.
Is it possible to make it fullscreen temporarily when a user presses a button? And then go back to standard modal look when used presses another button?
To clarify, I'm not talking about modalPresentationStyle = .fullScreen BEFORE A is presented, I need to present A in a standard way and then stretch it to be fullscreen when needed.
Although if I write pseudo code it would be something like this:
class A: UIViewController {
#objc func goFullScreen(sender: UIButton) {
// pseudo code:
// modalPresentationStyle = .fullScreen
// go fullscreen, block `drag-to-dismiss` gesture, remove `cornerRadius`, set `self.view.frame = UIScreen.main.bounds`
}
#objc func cancelFullScreen(sender: UIButton) {
// pseudo code:
// modalPresentationStyle = .pageSheet
// return to the standard look of a modal view controller
}
}
I found UIAdaptivePresentationControllerDelegate.presentationControllerShouldDismiss method that intercepts drag to close gesture, but I don't see any way to go fullscreen.
Picture of what I am talking about:
ps. I know I can make a custom container view controller with a custom transition delegate but I'd like to know if it's possible to implement such behaviour with system classes because I basically need just to flip modalPresentationStyle property with some interpolation animation...
Also on the right I hide/show some UI elements, but still it's the same view controller
Hi I am new to Swift and am trying to build an app with multiple Views..
My first View(initial view) is embedded in navigation controller.
My Second View is embedded in Tab Bar Controller
My Third View is again embedded in a Navigation Controller.
The problem is that on my third view I see to navigation Controller with the top one taking me back to First View and the below one taking me to Second View.
Is it an incorrect way of doing this? I want to get rid of navigation bar that came from 1st view.
Thanks in anticipation.
PS : I had initially not attempted Navigation Bar on 3rd View.. but the problem was that I am also not able to map Bar Button Item and hence to embed the 3rd View too in a separate Navigation Controller
While it shows perfect in Xcode.. it shows 2 NavBar on the simulator
Not an elegant solution but still this can solve your problem. On your controller embed to UITabBarController where you have added Next Button. Add the below code on that controller class.
On ViewWillappear add show nav bar and on viewDidDisappear hide nav bar as shown in below code
ON viewWillAppear:
override func viewWillAppear(_ animated: Bool) {
self.navigationController.navigationBar.isHidden = false
}
ON viewDidDisappear:
override func viewDidDisappear(_ animated: Bool) {
self.navigationController.navigationBar.isHidden = true
}
I have a navigation controller where I have enabled hide on tap.It hides at first when I tap on the screen but when I tap again,the nav bar hides but the toolbar does not hide at all and it is obstructing my view. I have already tried settoolbarhidden and toolbar.hidden properties but it does not work.How do I solve this?
EDIT : I need to hide it only on this screen,I need the toolbar for other screens so thats why I have enabled shows toolbar.
EDIT 2 : Let me frame my question better.
When I enter the view controller :
Both navbar and toolbar hides because I have set it to hidden which is good
When I tap the screen :
Both navbar and toolbar shows because I have set it this way in the previous view controller.(If possible,Can I only show/hide the navigationbar on tap not the toolbar?
And lastly when I tap it again to hide both bars :
The navigation bar hides but the toolbar does not go away? This is my problem.
As Per your question you want to show tool bar on a particular viewController. View Controller viewWillAppear Function Hide ToolBar and viewDidDisappear show your tool bar it will show on other view controllers.
" Please check the navigation controller checkbox its disable or not.After that set this on your view controller before your profile view controller "
override func viewWillAppear(animated: Bool) {
self.navigationController?.toolbarHidden = true;
}
override func viewDidDisappear(animated: Bool) {
self.navigationController?.toolbarHidden = false;
}
I think it will resolve your issue.
I had the same problem.
The hideBarsOnTap only work if you placed smth in it. So if it is empty it will stay.
You could just put a blank imageView or Label there for example.
Or if you want it completely blank, your only option is to put a tabGestureRecognizer on your View!
In my storyboard, I have setup a navigation controller points to my MainVC, and it works just fine.
And now, I'm trying to add another view called "HelpVC", and I created one in the storyboard. It automatically shows the navigation bar on the top.
(MainVC segues to HelpVC)
However, I did everything else in code.
I had initWithView in the HelpVC which draws out the interface, BUT the navigation bar does not show up, so I can't go back to that previous view controller.
How do I make sure that the navigation bar shows up and works just like other view controllers? (segue back to the last view?)
It is not very clear from the post, but as I understood, you may want to try:
override func viewWillAppear(_ animated: Bool){
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = false
}
In my UITableView that I have setup using Storyboards, I need to be able to add a tool bar that sticks to the bottom of the view, it should not scroll.
Unlike this question: LINK I don't think I could add a TableView subview to a normal view and then just add a toolbar programmatically because I am using dynamic cells which seem a lot easier to integrate via Storyboards.
For now, this is what I am stuck with....
if you want show toolbar in one view controller which placed in some navigation controller.
select view controller in storyboard
in utilities, show "attribute inspector". select "bottom bar" style.
add bar button item
add code in view controller, to show and hide toolbar:
code:
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setToolbarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setToolbarHidden:YES animated:YES];
}
Very easy. Just click on the navigation controller. Then in Show Attributes Inspector then navigation controller then click on the shows toolbar.
Check the screen shot.
For Swift users, you can use the following code:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated);
self.navigationController?.setToolbarHidden(false, animated: animated)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated);
self.navigationController?.setToolbarHidden(true, animated: animated)
}
This remedy works for (2016) iOS 9.2.
We all hate how Apple makes us waste time in stuff that should be straightforward like this. I like step by step solutions for this type of silly problems, so I will share it with you!:
Select your View controller > Attribute Inspector > Select "Opaque
Toolbar"
Now, drag and drop a "Bar Button item to your Storyboard.
Select your newly dropped Bar Button Item > Atrribute Inspector >
System Icon > Select your favorite icon.
In the viewDidLoad() method of your View controller, add this code before anything else:
override func viewDidLoad(animated: Bool) {
self.navigationController?.setToolbarHidden(false, animated: true)
//the rest of code
}
You don't want that toolbar hanging around elsewhere, so add this inside your view to
hide it once the current window is dismissed:
-
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated);
self.navigationController?.setToolbarHidden(true, animated: animated)
}
Voila!
Drag a UIViewController into Storyboard
Drag a UIToolbar on top of the Storyboard's contents.
Drag a UITableView on top of the Storyboard's contents.
Link the tableview's delegate and datasource to your source code.
Although you won't be able to use UITableViewController as your linking class step 4 will allow you to link it to a regular UIViewController.
You'll need something like this in the header though
#interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
It'll look something like this in your storyboard:
I used an intermediate View Controller with a Container view to the table. Add the toolbar view to the intermediate, and make it look however you want (use UIButtons instead of UIBarButtonItem).
If you do this, have the container view stretch to the top of the screen and not the bottom of the nav bar or you'll pull your hair out trying to get the scroll insets right.
Some more details in a similar question https://stackoverflow.com/a/31878998/1042111