Black area with interactivePopGestureRecognizer when popping a view controller with visible nav bar to a one with hidden nav bar - ios

I have this ViewController #1 which is the root view controller of a navigation controller and has
self.navigationController.navigationBarHidden = YES;
ViewController #1 tells its navigation controller to push ViewController #2, which has
self.navigationController.navigationBarHidden = NO;
When I want to go back from ViewController #2 to ViewController #1 by swiping from the left side of the screen, I see my views as the screenshot I attached here. This is captured as I move my finger to the right, so as I keep swiping to the right, the black area on the top right gets smaller and smaller until ViewController #1 covers all the screen area.
I'm guessing that this is caused by the hidden/visible navigation bar difference between the two view controllers.
I'd like to learn if it's possible to get rid of this black area.

As discussed with HoanNguyen, I had put my code to hide/show the navigation bar on viewWillAppear/Disappear but finally I figured out that the trick was to set the values animated. Weird, but this solved my problem and the black area is now gone:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:self.shouldHideNavBar animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:!self.shouldHideNavBar animated:animated];
}

You should put your code set hidden/shown navigation in viewWillAppear or viewDidAppear.

Related

hideBottomBarOnPush not working on child views

Pushing using segues with parameter on performSegues will hide the bottom bar when hidesBottomBarOnPush is set to true, the problem is on the child view of the view that has been hidden you cannot show/unhide the bottom bar. Already tried hidesBottomBarOnPush = false. Is there any way to unhide the bottom bar when the parent view's bottom bar is hidden.
Edit:
If I use the tabBar.hidden a small white rect will be shown at the bottom of the view. And also another problem with that is, when I change to another tab then go back to the tab I'm working on, the child view is retained but tabBar becomes hidden.
Legend:
3rd view controller - is the parent view that push segues.
4th view controller - is the child view.
Hoping someone can help me with this problem.
if you want to hide the bottom bar in one particular view controller,and show in others, try this, i think this works better than hidesBottomBarOnPush
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.tabBarViewController.tabBar setHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear];
[self.tabBarViewController.tabBar setHidden:NO];
}

top navigation bar becomes visible when navigation back from push segue on iphone

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;
}

UITabBar is removed when pushed back on UITableViewController but not ViewController

I have an iPhone app, which has a UITabBar with 5 tabs in it, each of the 5 tabs have NavigationViewcontroller which push to other "sub" views as the user selects different options.
2 of the tabs are UItableViews and 3 are UIviews.
When I push from a UITableView to another uiview, then return to the original UITableView, the tab bar appears white instead of a is original bar with 5 tbs on it.
However if I do the same thing from one of the 3 UIView (which is are the tab bar) to another UIView, then return the tab bar is as fine.
I am using storyboards (for the second time) and I have checked the Atributes inspector in the navigation controller and the root views for the UIView that are working and the table UITableView that are not and I cannot see any difference.
My question is should they be the same?
I also use this code to try and stop the bar from being hidden in the init method of the first view and the tab view,
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed=NO;
}
return self;
Any help or pointers would be greatly appreciated as my reading has left me blank
Use the following way to hide the bottom bar. When pushed it hides the bottom bar and on popping it reveals back the bottom bar
- (void)pushNewViewController{
MyNewViewController *viewController = [self instantiateNewViewController];
viewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController: viewController animated:YES];
}

Hide navigationBar?

1) What is the difference between the three lines of code below?
2) Also why does only the third line of code work if I'm returning to a viewController and the previous viewController has set the navigationBar to hidden through the same approach [self.navigationController setNavigationBarHidden:NO] my assumption was that all three lines do the same thing?
self.navigationController.navigationBar.hidden = NO;
[self.navigationController.navigationBar setHidden:NO];
[self.navigationController setNavigationBarHidden:NO];
Follow up:
Why when I need to run this code:
[self.navigationController.navigationBar setBackgroundImage:incorrectAnswerNavigationBarBackgroundImage forBarMetrics:UIBarMetricsDefault];
It only works, working being setting the background image, otherwise the nav bar is just white.
if I have both these lines:
[self.navigationController setNavigationBarHidden:NO];
self.navigationController.navigationBar.hidden = NO;
If I leave out self.navigationController.navigationBar.hidden = NO; the space for the nav bar pops down but it's just white, there is no background image. If I have both lines it works and there is a background image.
The first two are functionally identical; the difference being one uses the dot notation while the other doesn't. These two methods both fire - (void) setHidden:(BOOL)hide on the navigationBar property on the navigation controller.
Now the third one is a completely different method. It's - (void) setNavigationBarHidden:(BOOL)hide and is defined on UINavigationController. The reason why this one works is this method is informing the navigation controller that you wish the navigation bar to be hidden while the first two manually set the navigation bar to be hidden. The first two's changes are undone if UINavigationController calls any methods that modify the hidden property of the navigation bar, hence why the setNavigationBarHidden: method was created so you'd have a way of informing UINavigationController that no matter what it does, it should hide the navigation bar and not change it to be showing.
EDIT: For the second part of this question, you actually need to be calling - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated on UINavigationController. That's the proper documented method for UINavigationController.

How do I draw main view underneath my UINavigationBar so when the bar shows/hides, the view is unaffected?

Here's the situation:
I am making an app for iPad w/ iOS 6 using Autolayout along with UINavigationController. What I am trying to do is:
Segue from one view controller to the next with a standard push segue.
When I arrive at the new view controller, hide the nav bar with animation.
As the nav bar hides, I want my view to not shift at all. In fact, I want my view to effectively be drawn underneath the nav bar from the beginning, so I'm left with no shifting or movement of content and no black bars. For reference, this is what happens in the Amazon Kindle app when you go into a book.
With my current code, the contents of my view shift up to fill in the void left by the UINavigationBar.
I've tried force-setting the frame of my UIViewController's view and my UINavigationController's view to the entire iPad screen in the viewWillAppear method of my viewcontroller but no dice. I've experimented w/ Constraints in Autolayout but that also didn't get me to where I wanted to go.
Any help you can give would be great!
Try following before animating the navigation bar:
self.navigationController.navigationBar.alpha = 0.99f;
I didn't try this but this should work.
Looks like you need to add custom navigation bar in your new view and animate it to disappear.
I think, hiding original Navigation bar of Navigation Controller without shifting the view is not possible.
Rather add UINavigationBar to xib file, bind it to IBOutlet uiNavigationBar and try following code
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
CGRect f = self.uiNavigationBar.frame;
f.origin = CGPointMake(f.origin.x, f.origin.y - 44);
self.uiNavigationBar.frame = f;
} completion:^(BOOL finished) {
NSLog(#"done");
}];
}

Resources