2009-08-25 85 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

相關問題