Reputation: 23283
I'm trying to hide my NavigationBar and the Status Bar (slide up animation) and I'm running into an issue.
When the status bar is visible, the origin point of every element that is at 0 point (x: 0) means right underneath the statusbar. However, when the statusbar is hidden, the 0 (x: 0) point updates to accomodate the new space, and 0 (x: 0) means the absolute top of the screen.
When I hide the status bar and rotate into landscape, the view autosizes and everything is shifted to use the status bar's space, and throws off my animation:
if (![[UIApplication sharedApplication] isStatusBarHidden]) {
// Change to fullscreen mode
// Hide status bar and navigation bar
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];
[UIView animateWithDuration:animationDuration animations:^{
navBar.frame = CGRectMake(navBar.frame.origin.x,
-navBar.frame.size.height-20,
navBar.frame.size.width,
navBar.frame.size.height);
} completion:^(BOOL finished) {
[navBar setHidden:TRUE];
}];
} else {
// Change to regular mode
// Show status bar and navigation bar
[navBar setHidden:FALSE];
[[UIApplication sharedApplication] setStatusBarHidden:NO
withAnimation:UIStatusBarAnimationSlide];
[UIView animateWithDuration:animationDuration animations:^{
navBar.frame = CGRectMake(navBar.frame.origin.x,
0,
navBar.frame.size.width,
navBar.frame.size.height);
} completion:^(BOOL finished) {
}];
}
Any suggestions?
EDIT: Here's what the screen looks like after rotation's relayout: Image
Upvotes: 0
Views: 1346
Reputation: 2558
You're confusing the subdivision of the screen into UIView areas a little bit.
When you're in a navigation controller, there are three views:
So the Nav controller is managing it's own root view. In that it is filling the space with a NavigationBar at the top, and the rest of the area with one big UIView for content.
When you push your view controller onto the navigation stack, the Nav controller is adding your root view as the content. So your entire "self.view" is completely contained within the Nav controller's "content" view.
And so, of course, when the Nav controller hides the navigation bar... the "content" view expands up to fill the space. And then that view tells your view "hey, there's more space than you're using so your view also expands up to completely fill the Nav controller's content view.
So your view's "0" point is always the top of your view. That never changes. What is changing is where "the top of your view" is relative to the top edge of the screen.
If you want your content to remain in same spot on screen when navbar is removed, then you're going to have to account for the fact that your "zero" point is now higher than it was when there was a nav bar pushing the content view down.
Upvotes: 1