I have a table view A which is segued to a view B.
In A, there is a nav bar on the top, and below is the table.
When I press a row in A's table, B is pushed.
In B's viewWillAppear, I have the following code.
-(void)viewWillAppear:(BOOL)animated
{
self.wantsFullScreenLayout = YES;
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
}
This makes extends the view so that below the status bar, I have Nav bar and the UIView overlapped.
I also have viewWillDisappear
-(void)viewWillDisappear:(BOOL)animated
{
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
// back button was pressed. We know this is true because self is no longer in the navigation stack.
self.wantsFullScreenLayout = NO;
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"navigationbar_bg.png"] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.translucent = NO;
}
}
So when the user press back button, it will undo the fullscreen mode so that the view and nav bar won't overlap. THE ISSUE IS, when I press back button and the previous screen A is shown, strangely the table view still appears overlapped with the nav bar.
I even tried to put self.wantsFullScreenLayout = NO in A's willViewAppear but to no avail.
Shouldn't A shrink the tableview and be located under Nav bar? Can anyone let me know what is worng and how to solve this issue?
Thanks in advance!
Instead of putting the code in viewWillDisappear method, try to put the same code in the viewWillAppear method of the previous view controller.
Related
First. set alpha = 0.
click HOME back to backgroud, then click app back to app.
The alpha will set 1 auto automaticly.
How to set the navigationBar alpha = 0 forever.
If you want programatically try this:
If you want no navigation bar, and you want the content to be adjusted up to where the navigation bar normally would be, you should use
self.navigationController.navigationBarHidden = YES;
Otherwise use self.navigationController.navigationBar.hidden = YES; gives you a space where the navigationBar is.
when you come back from second view controller to first view controller then you have to implement some code in viewWillAppear method :
code
viewController1
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
self.navigationController.navigationBarHidden = YES;
}
viewController2
[self.navigationController popViewControllerAnimated:YES];
I'm hiding the navigationbar on a certain view, and when the user presses a button on the view, i'm pushing it to the next view.
In the next view, I am not longer hiding the nav bar and as expected it becomes visible. When hitting back however, the navbar on the first view also becomes (somehow) visible.
I'm hiding the top navbar like this:
self.navigationController.navigationBar.hidden = YES;
And I'm making it visible like this:
self.navigationController.navigationBar.hidden = NO;
I wonder what could be wrong with this, as it's quite basic but somehow has a glitch.
In Parent VC's viewWillAppear method hide the navigation bar.
-(void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBar.hidden = YES;
}
my app is structured as follow: UITabBarController > UINavigationController > ViewControllerOne > ViewControllerTwo.
the UINavigationBar has at the bottom the tab bar, now when the user navigates into the second view controller, i want to be able to hide the tab bar and replace is with a tool bar. i tried this code:
[self.navigationController.tabBarController.tabBar setHidden:YES];
[self.navigationController.toolbar setHidden:NO];
when i run the app the tab bar is hidden but the toolbar doesn't appear. plus, since the last VC is a table view controller, when i scroll through the cells there is a white gap between the table and the bottom of the view. how can i fix that?
That won't work because when you hide the tab bar like that the subviews won't be adjusted properly (that's why you get the white space). You'll have to use
self.hidesBottomBarWhenPushed = YES;
In your init method or awakeFromNib... and then
[self.navigationController setToolbarHidden:NO animated:YES];
In the viewDidLoad for example.
That way the tab bar controller's view is going to layout correctly it's subviews when you hide the tab bar. Just remember to call self.hidesBottomBarWhenPushed = NO; in your first view controller otherwise the tab bar is still going to be hidden when the second view controller is popped from the navigation stack.
Try to assigning toolbar with appropriate frame and adding it to self.tabBarController.view
I have a view controller, in which the navigation bar is transparent. My next view is a table view, in which the navigation bar is white.
To stop an unwanted animation carrying over, I am setting the navigation bar to transparent in the 'viewDidDissapear' of the table view. Unfortunately this leaves me with the image below when I navigate back (its even worse when you navigate forward). Does anyone know how to get rid of the black area?
-(void)viewWillDisappear:(BOOL)animated {
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
[super viewWillDisappear:NO];
}
This is the code I'm using in the table view controller.
As you said, UNWANTED ANIMATIONS ,. i would suggest you to set (animated:NO) in both (presentViewController & dismissViewController) of your tableViewController……… and set your navigation bars in viewWillAppear of both controllers.. best and easy i think..
I have a view controller which proceeds via a button to a table view controller.
In the view controller, the navigation bar is totally translucent (As you can see in the screen shot below). On the table view controller, the navigation bar is set to white.
My problem is, when I press 'back' in the table view and return to the view controller, the white navigation bar is carried over for a moment (see top image) before disappearing in an ugly animation.
Extra Navigation bar space:
How I want it to always look:
I have tried pretty much everything I can think of, all my code relating to the navigation bars translucency is in viewDidAppear, so why is this happening!?
Someone please tell me what I'm doing wrong! This is making me crazy!
In the tableviewcontroller set:
- (void)viewWillDisappear:(BOOL)animated {
// put the code for the uinavigation bar styling here.
}
You can do some thing like this have a custom back button below is the code
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(2, 1, 29, 29);
[backButton setBackgroundImage:[UIImage imageNamed:#"back_button"] forState:UIControlStateNormal];
[backButton addTarget:self action:#selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
backButton.adjustsImageWhenHighlighted = NO
item.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
where item is instance of UINavigationItem
and in selector of back button
-(void)backButtonClicked:(id)sender {
[self.navigationBar popNavigationItemAnimated:NO];
}
by doing this the navigation bar will pop the item but without animation.