In My Application,
I have Navigation Controller with root view controller.
To show/hide navigation bar which works fine.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
BOOL navbarhide=[self.navigationController.navigationBar isHidden];
[self.navigationController setNavigationBarHidden:!navbarhide animated:YES];
}
Works good but,
When navigation bar is hidden then view frame changes.
When navigation bar is not hidden then view frame changes.
Thanks in Advance...
Edit Setting set self.view.frame does not make any effect.
I have the same problem. In my project, it is because the view is scroll view. If your view is a scroll view or table view, you can try this:
I add below code to the controller.
self.automaticallyAdjustsScrollViewInsets = NO;
Hope it can help you.
You cannot change the frame of self.view
. I don't use setNavigationBarHidden:
to hidden the navigation bar, but directly change the frame of self.navigationController.navigationBar. In this way, self.view.frame
won't change.
CGRect frame = (navBarhidden) ? CGRectMake(0, -24,self.view.bounds.size.width,44) : CGRectMake(0, 20,self.view.bounds.size.width,44);
self.navigationController.navigationBar.frame = frame;
I had this problem while displaying UIView fullscreen. Resizing frame worked for me. (Swift)
hiding navigationBar:
self.navigationController!.navigationBar.hidden = true
self.view.frame.origin.y -= 64
self.view.frame.size.height += 64.0
showing navigationBar again:
self.navigationController!.navigationBar.hidden = false
self.view.frame.origin.y += 64
self.view.frame.size.height -= 64.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With