Adding a TabBarController as a View SubLanguage

I load the screen saver when the application starts. Then I want to load TabBarController and ViewControllers. However, the TabBarController window does not scale to screen size.

Probably 3/4 of the TabBar is cropped from the bottom, and at the top of the screen below the status bar is a thin 20-pixel gap. How to resize TabBarController correctly?

Here is the code in my SplashViewController loading the splash view and 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]; } 
+4
source share
2 answers

I finally found this to work. Instead:

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

or

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

Since I could not find automatic or named settings for this size, I had to create my own rectangle whose screen size is minus statusBar.

  tabBarController.view.frame = CGRectMake(0,0,320,460); 
+5
source

I just finished almost the same thing and ran into the same problems, but in the end I got his job.

  • 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 
  • Create an XIB view called Test1View

  • Add TabBarViewController in XIB

  • Set the file owner in XIB as Test1ViewController .

  • Connect tbc IBOutlet in the file owner to the tab bar controller in XIB.

  • Connect the view IBOutlet in the file owner to the view in XIB.

  • In your SplashViewController.h add property

     Test1ViewController *tabBarViewController; 
  • Synthesize TabBarViewController in SplashViewController.m .

  • Replace the TabBarController creation TabBarController in the TabBarController method in the SplashViewController as follows:

     tabBarViewController = [[Test1ViewController alloc] initWithNibName: @"Test1View" bundle:[NSBundle mainBundle]]; tabBarViewController.view.alpha = 0.0; [self.view addSubview:[tabBarViewController view]]; 
  • Here is a bit that I missed. In Test1ViewController.m you need to add the following line to the viewDidLoad method:

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

     -(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]; } 

Hope this helps.

+12
source

All Articles