View outside screen - iphone

I have a tab controller, which contains a navigation controller which again contains a view controller. The view controller shows a tab bar and a navigation bar.
In this view controller I want to add a full screen view (hides the tab bar and the navigation bar but leaves the status bar) which is shown during loading. I have subclassed UIView and set up a layout in a nib file which is loaded to this view:
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
// Load nib
self = [[[NSBundle mainBundle] loadNibNamed:#"FrontpageCountdownView" owner:self options:nil] objectAtIndex:0];
}
}
I add this view in the view controller like this:
// Hide tab bar and navigation bar
self.tabBarController.tabBar.hidden = YES;
self.navigationController.navigationBar.hidden = YES;
// Add loading (frontpage countdown) view
CGRect frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
NFFrontpageCountdownView *countdownView = [[NFFrontpageCountdownView alloc] initWithFrame:frame];
[self.view addSubview:countdownView];
The view in my nib has a size of 460 (full screen, minus the status bar). My problem is, that when I add it to the view controller it appears "bigger".
I would think that since the view has a size of 460 it should show the entire view when it is added to the view controller but it doesn't show the bottom. It seems that the view is too big even though it is 460 pixels.
Can anybody tell me why this is?
EDIT
How my view looks in Interface Builder:
How my view looks in the simulator:

This happens when hiding the tab bar using self.tabBarController.tabBar.hidden = YES.
Instead, you should hide it and then extend the view of the tabBarController.
CGRect tabBarFrame = self.tabBarController.view.frame;
tabBarFrame.size.height += self.tabBarController.tabBar.frame.size.height;
self.tabBarController.view.frame = tabBarFrame;
self.tabBarController.tabBar.hidden = YES;

Related

Accessing UITabBarController's content view

Is there a way to access the content view (shown as Custom content on the diagram) in order to change its frame?
Access to selected view controller's view in tab bar
UIView *view = tabBarController.selectedViewController.view;
Access to second view controller's view in tab bar
UIView *view2 = [(UIViewController*)[tabBarController.viewControllers objectAtIndex:1] view];

iPhone - App with tab bar controller - showing gap at top

I'm having a login view that accepts username and password. Upon successful authentication, i'll present a view controller that has tab bar view (IBOutlet) with 3 tabs. Each tab bar view controller has navigation controller (but no table view in any of the view controllers). Usign xib, i added tab bar controller object, then added navigation controllers under tab bar tree and added view controllers accordingly to the 3 navigation controllers.
Upon successful authentication, i'm calling
[self presentViewController:myViewController animated:YES]
This is how its being shown.
In myViewController's viewDidLoad, I'm adding tab bar as follows:
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.tabBarController.view];
}
Why is the gap seen above nav bar and below status bar. Due to that gap, tab bar at the bottom is being cut.......
It is a common problem, the tabBarController and also other Controller have by default the statusbar in its frame cordinates to resolve this, just set the bounds of your view to the frame of the tabBarController view.
tabBarController.view.frame = self.view.bounds;
In a case self.view.bounds was not in accurate position. So following was helpful to me.
self.view.frame = [[UIScreen mainScreen] bounds];
CGRect cgp = self.view.bounds;
[self.tabBarController.view setFrame:cgp];
In another case(iOS 7) tabBar hides itself to the bottom of screen. In this case
self.view.frame = [[UIScreen mainScreen] bounds];
CGRect cgp = self.view.bounds;
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
cgp.size.height = cgp.size.height-90;
}
[self.tabBarController.view setFrame:cgp];

Child view offset by 20 pixels in TabBar application

I have a tab bar application and when I display a modal view controller, the content screen is offset by about 20 pixels to the top and left. It looks like this:
I'm presenting this view from the child view controller (detail view) of navigation controller (main view) of the tabview.
When I show the view, I'm hiding the tab bar and navigation bar but status bar is kept visible. Adjusting the view to be centered (through Interface Builder's Simulated Interface Elements->View Mode : Center) and changing the view's frame after a call to 'viewDidLoad' in the controller doesn't seem to shift it.
- (void)viewDidLoad {
// this still doesn't cause it to shift
self.view.frame = CGRectMake(0, 20, 320, 460);
}
What's the way to adjust this so that the content area is shown correctly?
I launch the child view like this:
[detailController presentModalViewController:tvc animated:NO];
The app's view controller hierarchy:
Tab view with two child navigation controllers are created in the app delegate and the nav controllers added to the TabBar's view controllers:
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:tab1ViewController,
tab2ViewController, nil];
[window addSubview:tabBarController.view];
Each view controllers of the tab is created as a NavigationController with 1 view controller:
// MainViewController inherits from UIViewController
[MainViewController *viewController = [[MainViewController alloc] initWithNib..];
tab1ViewController.viewControllers = [NSArray arrayWithObject:viewController];
A detail view controller is launched with 'pushViewController' as a result of some action on tab1ViewController :
DetailController *detailController = [[DetailController alloc]
initWithNibName:#"DetailView"
bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:detailController animated:YES];
[detailController release];
It's from the detailController that I'm trying to launch the problem controller.
Some things to check right off: is "viewDidLoad" actually getting called?
If so, what is self.view.frame set to after the assignment?
Put an NSLog at the end that prints out the x, y, width, height, and see what's there.
Also, since the trouble vc is modal, it will occupy the entire screen.
"On iPhone and iPod touch devices, the view of modalViewController is always presented full screen."
HTH,
Mike

how to hide tabbar while pressing tab bar item?

In my application tab bar controller is used to show more than one views.I want to hide the Tab bar at the time of pressing first tab bar item.
But,I don't know how to do this...Plz help me to do this...
Thank You,
Renya
There are two methods in the tab bar control delegate protocol you should try:
– tabBarController:shouldSelectViewController:
– tabBarController:didSelectViewController:
You can hide the tab bar by calling calling tabBarController.controller.hidden = YES in the implementation of one these methods.
Note that the tab bar controller has two views; the tab bar and another view that contains the main content. I expect that you'll want to resize this content view too:
//remove the tab bars and resize the main view to fill the screen
UITabBar *tabBar = tabBarController.tabBar;
tabBar.hidden = YES;
UIView *mainView;
for (UIView * possibleMainView in [self.view subviews])
{
if (![possibleMainView isKindOfClass:[UITabBar class]])
{
mainView = possibleMainView;
break;
}
}
CGRect mainViewFrame = mainView.frame;
mainViewFrame.size.height += tabBar.frame.size.height;
mainViewFrame.origin.y = 0;
mainView.frame = mainViewFrame;

Keep Toolbar at top of UIView when using pushViewController and then popViewController?

Update: Another solution to this problem would be if the Navigation bar at the root level of the navigation controller could be transparent or not shown. Is there a way to make the Navigation bar at the root level of the navigation controller transparent or not shown?
I have a NIB with a toolbar at the top of my top level UIView and below the toolbar is a tableView. When I use pushViewController on a navigationController to push another UIViewController onto the navigationController, the toolbar is overwritten by the navigation bar. When I pop the current view back to the root view, the toolbar cannot be seen as there is a blank bar across the top. There is now also a gap between the toolbar and the top of the tableView about the size of the toolbar. So the view looks like from the top:
1) shaded blank bar,
2) blank space about the size of a toolbar,
3) tableview
How can I make the toolbar of the top level NIB appear at the top of the UIView after using popViewController?
In the top level view I instantiate a UINavigationController:
self.navigationController = [[UINavigationController alloc] initWithRootViewController:ListsController];
and then in didSelectRowAtIndexPath I push a view controller
ItemsController * Items = [[ItemsController alloc]
initWithNibName:#"Items" bundle:nil] ;
[self.navigationController pushViewController:Items animated:YES];
To get the initial pushed view to display I do the following:
UIView *navView = self.navigationController.view;
CGRect navFrame = navView.frame;
// navFrame.origin.y -= 20;
navView.frame = navFrame;
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UIWindow *appWindow = appDelegate.window;
[appWindow addSubview:navView];
Any idea how I can get the top level toolbar not to be overwritten when popping back to the top level?
The solution is to make the navigation bar hidden at the root level using:
- (void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:YES animated:YES];
[super viewWillAppear:animated];
[self.table reloadData];
}
Then at the next lower level of the navigation stack, make the navigation bar unhidden:
- (void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
[super viewWillAppear:animated];
[self.table reloadData];
}