i am using this in my view didlod
[self.navigationController setNavigationBarHidden:YES];
it hides when applicationn launches but when i navigate to next screen and come back to main view is not hide it navigation bar...
why is it like that?
should i add any thing ?
....
This works for me:
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
You wouldn't then need the one in viewDidLoad.
If it's not clear from that change, the reason your original code didn't work is that the view may be kept in memory even if it is not on screen - so need to hide / display the navigation bar each time the view is brought on or off screen.
viewDidLoad only fires the first time it loads your view. viewWillAppear fires every time.
Related
I have an app where the first screen (the menu for the app) does not need a navigation bar BUT the rest of the app does.
The code I am using works fine in the sense that the navigation bar is not present on the menu screen and is present elsewhere in the app BUT the BIG PROBLEM is that once you go back to the menu the navigation bar appears for about a split second and then disappears.
That is NOT a very smooth transition.
How do I make the transition SMOOTHER so that the navigation bar DOESN'T even appear for a second when I go back to the menu screen?
Here is the code that I am using:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
return self;
}
- (void)viewDidLoad {
[self.navigationController setNavigationBarHidden:YES animated:NO];
[super viewDidLoad];
}
-(void) viewDidAppear: (BOOL)animated {
[[self navigationController] setNavigationBarHidden:YES animated:NO];
[super viewDidAppear:animated];
}
Try like this,
-(void) viewWillAppear: (BOOL)animated {
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
Hope it may helps you...
In your first view controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
In your second view controller (not needed, but good practice for code clarity) :
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
set this in the view did disappear in first screen of the app
[[self navigationController] setNavigationBarHidden:NO animated:YES];
and this in viewdiddisappear of the second VC
[self.navigationController setNavigationBarHidden:YES animated:NO];
Instead of hiding and showing the navigation bar, you can update the alpha for the navigation bar. It will animate smoothly during the transition. For the view controller with transparent nav bar, instead of modifying the nav bar, create a navbar (or just the back button and title etc.) manually in the second controller's view. We will then hide the navbar when transitioning from first view controller to the second one.
On your second controller's viewWillDisappear and on your first view controller's viewWillAppear:, set the navigation bar alpha to zero using self.navigationController.navigationBar.alpha = 0;. Since this is in animation block, this will make the navigation bar disappear during the push animation.
Set the alpha back to one in second controller's viewWillAppear and first controller viewWillDisappear.
I have a navigation based app with 2 controllers: vA and vB.
vA is the navigation controller's root view controller and it is a full screen controller, so when this controller is being shown, the navigation bar is hidden.
Then I push vB using
[self.navigationController pushViewController:vB animated:YES];
On vB's viewDidLoad I have this:
self.navigationController.navigationBarHidden = NO;
// then I have navigation buttons defined here
The animation of vB entering the screen from the right happens this way:
the navigationBar suddenly appears on vA
vB slides from the right and fills the screen.
when I pop vB out, this is what happens
vB slides to the left showing vA behind.
at this time, we see vA with the navigationBar visible on top. Remembers vA should have no navigation bar visible. Then, that navigation vanishes and vA resizes to full screen.
this animation has no grace, is terrible, clunky and wrong.
What I want is this: the navigation slides in and out together with vB.
how do I do that?
thanks.
You need to use the animated version of the method you used in vcB's viewDidLoad:
[self.navigationController setNavigationBarHidden:NO animated:YES];
After edit: It seems to work fine in either viewDidLoad or viewWillAppear (but not viewDidAppear). It needs to be in viewWillDisappear for going back.
Try the following:
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewDidDisappear:animated];
}
// OR viewWillDisappear as mentioned by #RubberDuck
Instead of hiding navigation bar in viewDidLoad, implement viewWillAppear and viewDidDisappear
I'm using the following code to hide my navigationBar in the detailViewController(my second view),
and it works perfectly fine when I tap any of my object from the MasterViewController(my first view).
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
However, when I filter the table list in the masterViewController using searchDisplayController
and tap any object from the result, the navigationBar in the detailView doesn't get hidden...
Do I have to do any extra work to hide the navigationBar if I use the searchDisplayController?
for Debug, I set the break point on the line of setNavigationBarHidden:YES, and even if
I go to the detailViewController via search result, the application hits the line..
you shuold put [self.navigationController setNavigationBarHidden:YES]; in viewWillLayoutSubviews function.like this:
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
[self.navigationController setNavigationBarHidden:YES];
}
it works.
You should try this method:
In that controller, where you declared UISearchController *searchController, you should implement two methods (only for example):
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// if you want to hide Navigation Bar when searchController will become active
_searchController.hidesNavigationBarDuringPresentation = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
_searchController.hidesNavigationBarDuringPresentation = NO;
}
The code above may have differences. Main point in hidesNavigationBarDuringPresentation property (iOS 8.0 and later). Try to play with it, and turn to hidesNavigationBarDuringPresentation = NO before pushing a new controller. After this manipulations I took profit: when pushed UIViewController, setter setNavigationBarHidden:YES become working
if you want to hide Navigation bar then, In your MainWindow xib uncheck "Shows Navigation Bar" attributes of Navigation Controller.
This Will hide the Navigation Bar in your Whole Project. If you want to Show Navigation Bar in any Controller set NavigationBar Hidden = NO in ViewDidLoad Method of that Controller.
you should hack search display controller in some way to hide its built in navigationBar.
here is the answer:
https://stackoverflow.com/a/6337037/1348121
This
- (void) viewWillLayoutSubviews
causes layout problems, so i used code below. Works fine for me.
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO];
}
In my application i want to hide the navigation bar when i m going to previous view and i m hiding navigation bar in viewwiilldisaapper method but the effect is remaining mean it gives the white screen at the time of pop..
so can any one tell me the solution for it.
Thanks to all.
you need to hide navigation bar on viewWillAppear of that page by using
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void) viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}
if you need to hide navigation bar in certain condition then you need to put proper if else statements, so use this info with your logic according to your condition.
And view is automatic adjusted so no white space you get after pop but you get at time of pop.(no solution for this).
(void) viewWillDisappear:(BOOL)animated
{
if (self.navigationController.topViewController != self)
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
[super viewWillDisappear:animated];
}
I think it happen due to customize navigation bar. Is this right?
If you have customize navigation bar then you need to resize your upcoming
view. It doesn't matter how would you hide it.
I have a UISearchDisplayController setup with a UITableViewController which is nested inside a UINavigationController. When a selection of a cell is made, UITableView's didSelectRowAtIndexPath method is triggered, which pushes a new view to the parent navigation controller. This new view should have the navigation bar hidden on entry.
[[self navigationController] setNavigationBarHidden:YES animated:NO];
I use this line in the didSelectRowAtIndexPath method to hide the navigation bar. This works fine when a row is selected not using the search controller, but is overridden when selecting a search result. It seems the UISearchDisplayController takes it in its right to un-hide the navigationBar sometime after the row is selected.
If I move the setNavigationBarHidden call into the target view's viewWillAppear method, results are similar. I can make it work by placing the hide call in viewDidAppear, but this makes for a very awkward transition effect which feels jumpy and out of place. I would like to make the navigationBar already hidden before the new view slides on to the screen.
Does anyone know where the unhiding of the navigationBar is occurring, and/or any way I can override this behaviour?
This may not be the most elegant solution, but I believe it does exactly what you'd want it to. I came across a similar problem, and my solution was to have a method which hides the navigation bar, which is called after a delay of 0 seconds as follows.
The method that is called is:
-(void) hideNavBar {
if (self.navigationController.navigationBar.hidden == NO)
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
}
Then in the viewDidLoad method, I have the following:
[self performSelector:#selector(hideNavBar) withObject:nil afterDelay:0.0];
This works and removes the navigation bar in one instantaneous swoop. You can amend the delay time if you want the animation or for it to be removed after a delay. I tried [self hideNavBar] but that simply did not work, so sticking to what I have above.
Hope this helps, and if someone has a more elegant solution, I'm interested!
Ok, this bugged me for the a couple of hours, but I finally got it to work! The problem seems to be that the UISearchDisplayController keeps track of whether or not it has hid the navigation bar, and if it has, it restore it, after the view has been dismissed. That is why with many of the answers above you see the tail end of the animation of the bar hiding itself when the new view is pushed. However, by tricking the search display controller we can change this behavior.
First: Subclass The UISearchDisplayController
Following the answer on how to keep a navigation controller from hiding, found here, I altered the code, to keep the navigation bar hidden:
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
if(self.active == visible)
return;
[self.searchContentsController.navigationController setNavigationBarHidden:YES animated:YES];
[super setActive:visible animated:animated];
if (visible)
[self.searchBar becomeFirstResponder];
else{
[self.searchBar resignFirstResponder];
[self.searchContentsController.navigationController setNavigationBarHidden:NO animated:YES];
}
}
Note we hide the navbar before we call the super setActive function. This seems to keep the super class from trying to hide the nav bar and consequently, from trying to restore it ater item selection. Now when the controller becomes active, the bar will be hidden like normal. Also note that we restore the navigation bar when the searchBar resigns first responder. This will restore the bar if we cancel out of the controller.
Second: Hide Navigation Bar When Exiting
If we hide the navigation bar in the view will disappear, it will be hidden:
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
Third: Hide Navigation Bar When Returning
The only problem now is that if we select a row from the filtered tableview, when we return, the navigation bar will be visible. To fix this we need to put a check in view will Appear:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(self.isFiltered){
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
}
While this feels like a huge hack, it does the trick and I could see no better way of doing it.
Bumped into the same problem, managed to get it working smoothly with this ugly hack:
- (void) viewWillDisappear: (BOOL) animated
{
if (searchController_.active)
{
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
self.navigationController.navigationBar.tintColor = nil;
}
[super viewWillDisappear: animated];
}
- (void) viewWillAppear: (BOOL) animated
{
if (searchController_.active)
{
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
}
[super viewWillAppear: animated];
}
I had the same problem: my view has the navigation bar hidden by default and here's the way to keep it hidden:
-(void) viewWillLayoutSubviews{
if (self.navigationController.navigationBar.hidden == NO)
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
}
This way the navigation bar doesn't appear even after the search bar has been used.
- (void) viewWillDisappear: (BOOL) animated
{
// self.searchOn property tell if full screen search is enabled
//if (self.searchOn)
//{
[self.navigationController setNavigationBarHidden:NO animated:NO];
//}
[super viewWillDisappear: animated];
}
- (void) viewWillAppear: (BOOL) animated
{
//if (self.searchOn)
//{
[self.navigationController setNavigationBarHidden:YES animated:YES];
//}
[super viewWillAppear: animated];
}