Shivbaba's son
Shivbaba's son

Reputation: 1369

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.

Upvotes: 6

Views: 7429

Answers (7)

Rinju  Jain
Rinju Jain

Reputation: 1694

scrollView.contentInsetAdjustmentBehavior = .never

Upvotes: 0

ciessielski
ciessielski

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

JZAU
JZAU

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

nova
nova

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

Tendulkar
Tendulkar

Reputation: 5540

change the self.view.frame when you are showing and hiding the navigation bars

Upvotes: 0

NIKHIL
NIKHIL

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

V.J.
V.J.

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

Related Questions