views:

4102

answers:

6

I am loading a splash screen when my app starts. Then I want to load a TabBarController and it's ViewControllers. However, my TabBarController window does not scale to the screen size.

Probably 3/4 of the TabBar at the bottom is getting cut off and There is a slim aprox 20 pixel gap at the top of the screen below the status bar. How do I resize the TabBarController properly?

Here is the code in my SplashViewController loading the splash view, and the TabBarController:

 -(void)loadView{
// Init the view
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
UIView *view = [[UIView alloc] initWithFrame:appFrame];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.view = view;
[view release];

splashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Splash.png"]];
splashImageView.frame = CGRectMake(0,0,320,458);
[self.view addSubview:splashImageView];

viewController = [[FlashCardViewController alloc] initWithNibName:@"FlashCardViewController"  bundle:[NSBundle mainBundle]];
//viewController.view.bounds = [[UIScreen mainScreen]bounds];
viewController.title = @"Quiz";
viewController.tabBarItem.image = [UIImage imageNamed:@"puzzle.png"];

UIViewController *viewController2 = [[UIViewController alloc] initWithNibName:nil  bundle:nil];
viewController2.title = @"Nada";
viewController2.tabBarItem.image = [UIImage imageNamed:@"magnifying-glass.png"];
//viewController.view.alpha = 0.0;
//[self.view addSubview:viewController.view];

tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:viewController, viewController2, nil];
[viewController2 release];
tabBarController.view.alpha = 0.0;
//tabBarController.tabBarItem.image = [UIImage imageNamed:@"State_California.png"];
//tabBarController.tabBarItem.title = @"State_California.png";
tabBarController.view.bounds = [[self view] bounds];
//tabBarController.view.frame = [[UIScreen mainScreen] applicationFrame];
[self.view addSubview:tabBarController.view];

timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fadeScreen) userInfo:nil repeats:NO]; 
}
-(void) fadeScreen
{
[UIView beginAnimations:nil context:nil]; // begin animation block
[UIView setAnimationDuration:0.75]; // sets animation duration
[UIView setAnimationDelegate:self]; // sets the delegate for this block
[UIView setAnimationDidStopSelector:@selector(finishedFading)]; // Calls finishFading
self.view.alpha = 0.0; //  // Fades the alpha to 0 over animation
[UIView commitAnimations]; // Commits this block, done
}

-(void) finishedFading
{
[UIView beginAnimations:nil context:nil]; // Begin animation block
[UIView setAnimationDuration:0.75]; // set duration
self.view.alpha = 1.0; // fades the view to 1.0 alpha over .75 seconds
//viewController.view.alpha = 1.0;
tabBarController.view.alpha = 1.0;
[UIView commitAnimations];
[splashImageView removeFromSuperview];
}
A: 

I finally found someting that works. Instead of:

tabBarController.view.frame = [[UIScreen mainScreen] applicationFrame];

or

tabBarController.view.bounds = [[self view] bounds];

Because I couldn't find and automatic or named settings for this size, I had to create my own rectangle that is the size of the screen minus the statusBar.

 tabBarController.view.frame = CGRectMake(0,0,320,460);
Bryan
A: 

I am trying to do the same thing (transition from a splash screen - UIViewController) to a tab-bar controlled application (UITabBarController). I want to design it with IB for maintenance reasons and not manually build. I have tried starting with a UITabBarController and precede it with a UIViewController, but the two compete for the delegate ownership. I then switched to designing with the UIViewController and then, after the splash animation completes, transition to the UITabController. This did not have enough definition and hook-up from IB and I could not figure out the delegates, view hierarchy, resigning and pushing, etc.

I know it can be done, but I just cannot seem to figure out the logistics and I am defeated with random experimentation. The SDK doc does not have enough specific detail -- just high-level, architectural generalities.

I would like to keep this topic open until an answer with better design control is provided. I will keep surfing for answers, but this problem description is EXACTLY what I am trying to get answered. If someone knows of some good doc, tutorial, video, etc., that would be acceptable too.

-mobibob

mobibob
+2  A: 

I've just completed pretty much the same and ran into the same problems but eventually I got it working.

  1. Create a View Controller class in Xcode called Test1ViewController and add the following:

    @interface Test1ViewController : UIViewController {
        IBOutlet UITabBarController *tbc;
    }
    
    
    @property (nonatomic,retain) IBOutlet UITabBarController *tbc;
    @end
    
  2. Create a View XIB called Test1View

  3. Add a TabBarViewController to the XIB

  4. Set the File's Owner in the XIB to be the Test1ViewController.

  5. Connect the tbc IBOutlet in the File's Owner to the Tab Bar Controller in the XIB.

  6. Connect the view IBOutlet in the File's Owner to the View in the XIB.

  7. In your SplashViewController.h add the property

    Test1ViewController *tabBarViewController;
    
  8. Synthesize the tabBarViewController in your SplashViewController.m.

  9. Replace your TabBarController creation code in your loadView method in SplashViewController with the following:

    tabBarViewController = [[Test1ViewController alloc] initWithNibName:
            @"Test1View" bundle:[NSBundle mainBundle]];
    tabBarViewController.view.alpha = 0.0;
    [self.view addSubview:[tabBarViewController view]];
    
  10. Here's the bit that was missing for me. In Test1ViewController.m, you need to add the following line to the viewDidLoad method:

    self.view = tbc.view;
    
  11. Finally, I also had to change the finishedFading method in SplashViewController.m to set the alpha to 1.0 on the tabBarViewController view.

    -(void) finishedFading
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.75];
        self.view.alpha = 1.0;
        tabBarViewController.view.alpha = 1.0;
        [UIView commitAnimations];
        [splashImageView removeFromSuperview];
    }
    

I hope this helps.

Chris Dunne
Thanks, I was looking for something similar. Rated the thing up.
Wim Haanstra
A: 

THANK you Chris!!!!

I was trying to solve this problem for 3 days and once I read your posting it solved it !!!

CocoaNewBee
A: 

it work on os.3.1.3 but i test on os4 it not appear.

help me.

xnanoob
A: 

Thank you so much Chris...I was running to this problem for almost a week :-( you saved my day and now i go to celebrate :-) What was missing for you exactly was missing for me- That Stupid self.view = tbc.view;

wael