4

当我的应用程序启动时,我正在加载启动画面。然后我想加载一个 TabBarController 和它的 ViewControllers。但是,我的 TabBarController 窗口不会缩放到屏幕大小。

底部的 TabBar 可能有 3/4 被切断,并且在状态栏下方的屏幕顶部有一个大约 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];
}
4

2 回答 2

12

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

  1. 在 Xcode 中创建一个 View Controller 类,Test1ViewController并添加以下内容:

    @interface Test1ViewController : UIViewController {
        IBOutlet UITabBarController *tbc;
    }
    
    @property (nonatomic,retain) IBOutlet UITabBarController *tbc;
    @end
    
  2. 创建一个名为Test1View

  3. 添加TabBarViewController到 XIB

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

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

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

  7. 在您的 SplashViewController.h 添加属性

    Test1ViewController *tabBarViewController;
    
  8. tabBarViewController你的SplashViewController.m.

  9. 将您的方法中的TabBarController创建代码替换为以下内容:loadViewSplashViewController

    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. 最后,我还必须更改finishedFading方法以在视图SplashViewController.m上将 alpha 设置为 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];
    }
    

我希望这有帮助。

于 2009-10-02T15:25:47.373 回答
5

我终于找到了一些有用的东西。代替:

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

或者

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

因为我找不到这个大小的自动或命名设置,所以我必须创建自己的矩形,它是屏幕大小减去状态栏的大小。

 tabBarController.view.frame = CGRectMake(0,0,320,460);
于 2009-08-26T16:30:54.923 回答