I have three viewcontrollers all in a navigation stack. The first view controller does not utilize the uitoolbar, the second one does and the third one does not.
The problem is, when I go from the second UIViewController to the third UITableViewController, if I hide the toolbar, there is a white gap at the top of the screen.
Here's a picture:
I currently have [self.navigationController setToolbarHidden:YES animated:YES];
in the viewWillDisappear of the second view controller, but I've also put it in the third view controller's viewWillAppear method. Both cause the gap to appear.
How can I fix this?
First off, I'd recommend using setToolbarHidden:YES animated:NO to have the new UIViewController appear without the toolbar. I think your method will show it initially and then it disappears, right? If you use the animated:NO (or else use the method signature without animated:), the new UIViewController should "push" off the UIToolbar for the 2nd UIViewController when the 3rd UIViewController is pushed onto the screen.
Secondly, you probably need to have a look at your shocks and struts for your UIViewController's view in Interface Builder. That is almost certainly what's causing this gap. You probably want to have a fixed top and bottom margin and a flexible height.
I'll answer my own question, but I'm not going to accept it because it is hacky.
I was able to fix it by adding this line of code at the beginning of viewDidLoad:
[self.tableView setFrame: CGRectMake(0, 0, 320, 493)];
Basically, I set the tableview frame's height to be 13 pixels bigger than the size of a full screen (which is 320 x 480).
Related
I've been trying to add a UIView (with a UIImageView) as an initial screen when the user launches my application for the first time. However, even after I hide the tab bar, or move its frame out of the screen, the UIView still crops itself as if the tab bar was still there.
Both of these code blocks produced the same result:
[appDelegate.tabBarController.tabBar setFrame:CGRectMake(0,1000,0,0)];
[self setView:InitialView];
and
[appDelegate.tabBarController.tabBar setHidden:YES];
[self setView:InitialView];
Here's a screenshot of the incident in action:
Does anyone know how to fix this problem? I've been puzzling away at this for the past few hours, and I can't seem to do anything about it.
Presumably you have your view's view controller inside this tab bar controller. As a result, the view controller's view is getting sized appropriately to fit inside the tab bar controller's view. Why don't you just get the frame of the tab bar and adjust the height of your view by the view's current height + the tab bar's height?
As a side note, I am assuming InitialView is a UIView (or subclass) instance. It is standard Object-Oriented Programming convention to name instances of classes with a lower case letter, and then to proceed in camel case, as in initialView. Just an FYI.
Try this reference your App Delegate which should take in account the UITabBarController. Just the UIImageView as a subview, and when you are done just remove it. You'll obviously have to import your AppDelegate.
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
[imageView addSubview:appDelegate.window];
I recently started using interface builder, the problem i'm facing right now is when i use the back button of navigation controller, my UI elements' y axis go up by roughly 20-30 px, is there some setting i've to use to avoid this problem ? And they go up only when i use pushViewController, when i use popViewController it loads the way i need.
Code i'm using for pushing:
examVC=[[ExampleClass alloc] initWithNibName:#"ExampleClass" bundle:nil];
[[self navigationController] pushViewController:examVC animated:YES];
I'm attaching the images with the question. Please note how label has gone down about 20-30 px.
Why does this happen? What am i doing wrong ?
Thanks for all the help.
Edit : changed the screens for better clarity
I'm using pushing code on the round rect button.
Screen 1:UI elements set in my IB
Screen 2: How it looks when pushed from previous view
Screen 3: How it looks when popped from the "Next View"
My home view controller had the navigation bar hidden, the screen i posted was the second view which comes after the home view. I wanted to hide navigation bar in the first view only, so i had used :
- (void)viewDidDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewDidDisappear:animated];
}
It caused the problem because i was showing the navigation bar again in viewDidDisappear, so the view would load first then the navigation bar would be shown causing it to overlap.
So i put the same code in viewWillDisappear, which removed the issue. As navigation bar did load before loading of the next view. Now the view loads just like i designed it in interface builder.
Hey I don't know whether it will work for you or not but in your IB change top bar None to Navigation Bar
Then adjust your element accordingly and tun the code.
I tried all of the suggestions here and none of them worked. My UI elements were always lower when popping back to my original view controller. The only thing that fixed this for me was going into my nib file in Interface Builder and turning off Auto Layout.
I have a UINavigationController with two UIViewControllers. One of the ViewController hides the UIToolbar (the default UIToolbar from the UINavigationController) the other shows it. When I push the ViewController with the UIToolbar onto the ViewController without the UIToolbar the following happens:
The UIToolbar slides up from the bottom and fills a black gap in the new ViewController. This is very ugly since you can see the black background, which is different from the rest and the animation should ideally mirror the navigationbar animation (slide from right to left). When I pop the ViewController the opposite happens (hiding the UIToolbar slides down to the bottom and leaves a black gap in the popped ViewController)
I hope this makes sense. I just want the UIToolbar to mirror the navigationbar animation (slide from left to right (pop) and right to left (push) ).
I've done research here on SO but couldn't find a satisfactory answer. Is it possible to make the default UIToolbar behave in the manner I described or is it really necessary to create a custom UIToolbar and add it to the ViewController (which doesn't seem very logical since there is a perfectly good one readily available).
Thanks for you consideration!
Regards,
Ivo
when you turn on the toolbar, make sure to set it to not animate.
[[self navigationController] setToolbarHidden:NO animated:NO];
I do this in my viewWillAppear of my viewcontroller, and it seems to do the job ok.
in an iPad application, I am displaying a modal view controller (through presentModalViewController) in a FormSheet style (so it's about 540 pixels wide and high), the root view controller displays fine (its frame's size is set to roughly (540, 540) and my code takes care of laying out the content properly).
However, when a push a view controller, its frame's size always has (768, 1024) which is wrong. I tried to set its frame explicitly like this:
DetailViewController* detailController = [[DetailViewController alloc] init];
detailController.view.frame = self.view.frame;
[self.navigationController pushViewController:detailController animated:YES];
Any ideas why it doesn't set the size properly?
well, layoutSubviews should be used if the actual frame of the view at runtime is needed. I ended up using that to lay the subviews inside the controller's view. (although I had to create a custom UIView subclass for controller's view)
Your approach looks right. Forgive my question, but have you debugged this with breakpoints and GDB?
You might try this from the console (cmd shift r):
print [[self view] frame]
and
print [[detailController view] frame]
print this before and after you call pushViewController:animated on the UINavigationController to see if its frame size changes from the pushViewController:animated method.
Another note, its hard to see a use case for pushing a view controller to a UINavigationController that would NOT consume the entire UINavigationController's views area. Every push onto the navigation controller represents a level deeper into some navigation (unlike UIView - addSubView).
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
Update: This is why you are having problems:
The view is automatically resized to fit between the navigation bar and toolbar (if present) before it is displayed.
You will find that on apple's documentation on the link I provided. See pushViewController:animated:
View controllers are expected to manage an entire "screenful" of content. Only one view controller (not counting container controllers like UINavigationController) is active at any given moment. The only exception is UISplitViewController, which allows two view controllers to have content on the screen at once.
I've checked the other answers but have not found anything that really describes my situation. So here goes.
I have a window-based app that creates and loads a UIViewController from xib. It has status bar disabled, height of 480 and a UISegmentedControl with y origin of 451. It displays nicely at the bottom of the screen.*
In viewDidLoad of the UIViewController I create a UIView initWithFrame:CGRectMake(0.0, 0.0, 320.0, 431.0)]; (that's 480 - 29 pixels for the UISegmentedControl and 20 for the status bar.) I add it to the UIViewController with [self.view addSubview:gameBoard];. Then some UIView game pieces are added as subviews of the gameboard UIView and everything is displayed as I think it should be.
When some of those UIView subviews are tapped, a menu should appear. I have created a UIViewController with the required controls on it. I use a delegate method to call from the subviews, who pick up the triggering events, to the root UIViewController - which does
self.squadOrders = [[SquadOrders alloc] initWithNibName:#"SquadOrders" bundle:nil];
squadOrders.viewControllerDelegate = self;
[self presentModalViewController:squadOrders animated:YES];
And the modal dialog displays as I think it should, sliding up from the lower edge of the screen, not covering the status bar but covering the UISegmentedControl mentioned at the bottom of the root UIViewController. It gets dismissed by
[self dismissModalViewControllerAnimated:YES];
and that's where the trouble begins. The UISegmented control is moved down by 20 pixels so that only 9 pixels of it is visible at the bottom of the screen. There is a 20 pixel white gap at the top where the view has been moved down.
*enabling the status bar on this or any other xib does not change the described behavior at all.
Other stackoverflow questions related are:
IPhone - After dismissing Modal View Controller - gap is left at top of page - but the given solution was don't have another view controller loaded as a subview of the view controller that displays the modal - but I don't, only UIViews. There's also the suggestion of just resetting the appropriate frame after the modal goes away but it feels like cheating.
Contents of UIScrollView shifted after dismissing ModalViewController - I've played with the heights of all the views and controllers - am sure they match, hasn't helped. Again, the frame can be reset but it only addresses the symptom.
There are others but nothing is solving this issue so far.
I've just solved this issue with view shifting down.
It was because of navigationBar.barStyle set to UIBarStyleBlackTranslucent.
This is a hack, but might help somebody. I was having plenty of these 20 pixel gap issues throughout my app and they all went away by using a navigation controller as my root view controller. I don't really use it as a nav controller at all (and I hide the nav bar), so this solution can work in most apps.
Basically, I have a BaseView (320 x 480, no status bar) whose controller sits in my nav controller, and then the rest of my app is added as subviews to the BaseView. It all works great now.