2009-08-25 51 views
4

我在加载启动屏幕时启动应用程序。然后我想加载一个TabBarController,它是ViewControllers。但是,我的TabBarController窗口不会缩放到屏幕大小。添加TabBarController作为视图的子视图

底部可能有3/4的TabBar被切断,状态栏下方的屏幕顶部会出现一个细长的APROX 20像素间隙。如何正确调整TabBarController的大小?

这里是我的SplashViewController加载飞溅视图的代码,以及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]; 
} 

回答

5

我终于找到成才工程。相反的:

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

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

因为我无法找到和这种尺寸的自动或命名设置,我不得不创建我自己的矩形显示在屏幕减去状态栏的大小。

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

如果你在viewWillAppear中运行self.tabBarController.view.frame = [[self view] frame],它将工作,而你不必自己算出数字,因为那时边界和帧已被正确/完全计算。 – pulkitsinghal 2011-12-29 16:26:55

+0

会更好回答:tabBarController.view.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);因为宽度和高度根据用户使用的每个设备而有所不同? – lakesh 2013-02-14 10:49:15

12

我刚刚完成了几乎相同的工作,遇到了同样的问题,但最终我找到了工作。

  1. 在Xcode中创建一个视图控制器类叫做Test1ViewController并添加以下内容:

    @interface Test1ViewController : UIViewController { 
        IBOutlet UITabBarController *tbc; 
    } 
    
    @property (nonatomic,retain) IBOutlet UITabBarController *tbc; 
    @end 
    
  2. 创建视图XIB称为Test1View

  3. 添加TabBarViewController到厦门国际银行

  4. 将XIB中的文件所有者设置为Test1ViewController

  5. 将文件所有者中的tbc IBOutlet连接到XIB中的选项卡栏控制器。

  6. 将文件所有者中的view IBOutlet连接到XIB中的视图。

  7. 在你SplashViewController.h添加属性

    Test1ViewController *tabBarViewController; 
    
  8. 合成下你SplashViewController.mtabBarViewController

  9. 用以下替换您TabBarController创建代码在你loadView方法SplashViewController

    tabBarViewController = [[Test1ViewController alloc] initWithNibName: 
         @"Test1View" bundle:[NSBundle mainBundle]]; 
    tabBarViewController.view.alpha = 0.0; 
    [self.view addSubview:[tabBarViewController view]]; 
    
  10. 下面是失踪了我一下。在Test1ViewController.m,你需要添加下面一行到viewDidLoad方法:

    self.view = tbc.view; 
    
  11. 最后,我也不得不改变SplashViewController.mfinishedFading方法来设置透明度为1.0的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]; 
    } 
    

我希望这有助于。

+0

谢谢,我正在寻找类似的东西。评价这件事。 – 2010-10-12 14:26:55

+0

谢谢!我不能让我的生活得到它的工作,事实证明我错过了第10步。 – link664 2011-05-10 02:12:29

+0

几乎所有的答案都是死的 - 除了第10步。由于某种原因,现在不工作,也许它的iOS5事情?取而代之的是在viewWillAppear中放置self.tabBarController.view.frame = [[self view] frame],这对我来说是个诀窍。 – pulkitsinghal 2011-12-29 16:25:07

相关问题