Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View Frame Changes On Hide/Show Navigation Bar?

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.

When navigation bar is not hidden ..see the press button and view's origin is below the bar, I dont want like this I want it to stick at navigation bar's origin[at the top of the page]

It is fine view is at its original position when bar is hidden. I want view to be stick  at this position and turn bar hide/show without changing the view's frame.

Thanks in Advance...

Edit Setting set self.view.frame does not make any effect.

like image 318
Arpit B Parekh Avatar asked Oct 15 '11 05:10

Arpit B Parekh


3 Answers

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.

like image 83
JZAU Avatar answered Oct 13 '22 09:10

JZAU


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;
like image 28
nova Avatar answered Oct 13 '22 10:10

nova


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
like image 42
ciessielski Avatar answered Oct 13 '22 08:10

ciessielski