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.
Related
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 iPhone App there are three views, firstView, secondView and thirdView.
now I want to put Back Button in navigation bar in thirdView only which should take me to back secondView only
for that i m writing this code in first view
self.navigationItem.hidesBackButton:NO;
and it shows the back button in both the views secondView and thirdView
what I should do to hide back button in the the secondView?
I think you have to set [self.navigationItem setHidesBackButton:YES] in your secondView.
And set [self.navigationItem setHidesBackButton:NO] in your thirdView.
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationItem.backBarButtonItem=nil;
}
OR
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationItem.hidesBackButton=YES;
}
To hide the back button in the navigation bar
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
self.navigationController.navigationBar.topItem.hidesBackButton = YES;
}
To show the back button in the navigation bar
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
self.navigationController.navigationBar.topItem.hidesBackButton = 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 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.
The New York Times iPhone application has a Tab Bar with five tab bar items. When you select the Latest tab, the app shows the title and abstract/summary in a UITableView. When you select an individual story to read, the Tab Bar disappears and is replaced with a header and footer that appears/disappears depending on the state of the app. How does the app "hide" the tab bar?
Thanks!
Implement this piece of code in the class where you want to hide the Tab Bar.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
self.hidesBottomBarWhenPushed = YES;
return self;
}
All the best.
The view controller that is being pushed onto the navigation controller stack has its hidesBottomBarWhenPushed parameter set to yes. The code would look something like this in the table view's -didSelectRowAtIndexPath.
NSDictionary *newsItem = [newsItems objectAtIndex:[indexPath row]];
NewsDetailViewController *controller = [[NewsDetailViewController alloc] init];
[controller setHidesBottomBarWhenPushed:YES];
[controller setNewsItem:newsItem];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
Take a look at the documentation for hidesBottomBarWhenPushed.
p.s. You'll probably get more visibility on this question if you add the tag 'iphone' to it.
I have a view that needs to optionally (depending on some other state) show the navigation controller toolbar. This is the solution I used to show & hide the toolbar (with animation) when the view appears & disappears via navigation. It sounds like what you might be after.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Show the nav controller toolbar if needed
if (someBool)
[self.navigationController setToolbarHidden:NO animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Hide the nav controller toolbar (if visible)
[self.navigationController setToolbarHidden:YES animated:animated];
}