0
votes

I have a UINavigationController and its navigationBar hides if the user scrolls (done with UIScrollViewDelegate, not with pan gesture).

But when I push a a new viewController onto the stack, the new controller's view's origin y is at 64px and not where the old topViewController's y was (which is 21px).

How can I make the push, so that the new controller appears at the same position as the old one was?

The only place that updating the view's frame was successful was in viewDidAppear, but that's to late, because the user can see a black space on the top for a second.

Updated:

It seams like it has to be done between viewWillAppear and viewDidAppear, but I can not find reasonable method to do this.

Tried to alter the UINavigationController's view (currently I'm just moving it's navigationBar), but that messes up the layout.

Update again:

Some more info, because none of the answers and comments helped. The navigationcontroller is instantiated from storyboard. It's a custom UINavigationController, which hides the navigationBar on it's topViewController's scrollView scrolling (nothing else is overwritten).

The first topViewController (from which the push is started) is a UIViewController with 2 container view (one if logged in, other if not). The second topViewController (the one which is pushed onto the stack) is a UIViewController with a full screen UIWebView.

Everything is coming from the storyboard. All the Extended Edges checkboxes are off for every viewController and all the navigationBars are opaque. AutoLayout is used everywhere and (I think setup right).

1
Check whether your new ViewController's and the ViewController from which you are pushing has same navigationBar property. navigationBar.translucent and navigationBar.opaque These properties changes the originY of the ViewController's view.Srikanth
Thanks, but both of them are opaque.szotyi
In my app what I have done is, used a bool property to access whether the navigationBar was hidden in the viewController when pushing a new VC. In the viewWillAppear, I check if the navBar was hidden. If yes, I set it's frame. I'm not sure whether it's best practice, but it does the job.n00bProgrammer
This is what I'm trying to do, but setting in viewWillAppear doesn't work. When it gets to viewDidAppear the frame is back to the original. Something is altering the frame between viewWillAppear and viewDidAppear.szotyi

1 Answers

0
votes

--Edited--

change your frame in viewWillAppearmethod

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.view setFrame:CGRectMake(0, 21, self.view.frame.size.width, self.view.frame.size.height)];
}

or setFrame of your newController before to be pushed.

NewController *newC = [NewController alloc] initWithNibName:@"NewController" bundle:nil];
[newC.view setFrame:CGRectMake(0, 21, self.view.frame.size.width, self.view.frame.size.height)];

[self.navigationController pushViewController:newC animated: YES];