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
scrollView.contentInsetAdjustmentBehavior = .never
I think this is by default functionality which cannot be changed by you, but you change the position of the button by using following code
myButton.frame = CGRectMake(X, Y, Height, Width);
after hiding the navigation bar.
i think this may 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);
}
在显示和隐藏导航栏时更改self.view.frame
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.