View changes in a frame on the Hide / Show Navigation Bar screen?

In my application

I have a navigation controller with a root view controller.

Show / hide navigation bar that works great.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { BOOL navbarhide=[self.navigationController.navigationBar isHidden]; [self.navigationController setNavigationBarHidden:!navbarhide animated:YES]; } 

Works well but

When the navigation bar is hidden, change the frame borders.

If the navigation bar is not hidden, resize the frame.

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 at Advance ...

Changing the set self.view.frame setting has no effect.

+6
source share
6 answers

I have the same problem. In my project, this is because the view is a scroll. If your view is a scroll view or a table view, you can try the following:

I am adding the code below to the controller.

 self.automaticallyAdjustsScrollViewInsets = NO; 

Hope this helps you.

+10
source

You cannot change the self.view frame. I do not use setNavigationBarHidden: to hide the navigation bar, but directly change the frame self.navigationController.navigationBar. This way self.view.frame will not 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; 
+3
source

I had this problem when displaying fullscreen UIView. The resize 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 

the navigation bar is displayed again:

  self.navigationController!.navigationBar.hidden = false self.view.frame.origin.y += 64 self.view.frame.size.height -= 64.0 
+2
source

I think this is the default functionality that you cannot change, but you change the position of the button using the following code

myButton.frame = CGRectMake (X, Y, Height, Width);

after hiding the navigation bar.

0
source

I think it can help you.

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { BOOL navbarhide=[self.navigationController.navigationBar isHidden]; [self.navigationController setNavigationBarHidden:!navbarhide animated:YES]; if(navbarhide) self.view.frame=CGRectMake(0,0, 320, 480); else self.view.frame=CGRectMake(0,44, 320, 480); } 
0
source

change self.view.frame when you show and hide navigation bars

0
source

Source: https://habr.com/ru/post/899351/


All Articles