Reputation: 1369
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.
Upvotes: 6
Views: 7429
Reputation: 21
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
Upvotes: 2
Reputation: 3567
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.
Upvotes: 11
Reputation: 791
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;
Upvotes: 3
Reputation: 5540
change the self.view.frame when you are showing and hiding the navigation bars
Upvotes: 0
Reputation: 2719
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);
}
Upvotes: 0
Reputation: 9590
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.
Upvotes: 0