本文介绍了将TabBarController添加为视图的子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

大约底部的TabBar的3/4被切掉,状态栏下方的屏幕顶部有一个细长的aprox 20像素间隙。如何正确调整TabBarController的大小?

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?

这是SplashViewController中加载splash视图和TabBarController的代码:

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


推荐答案

。而不是:

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

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

因为我找不到这个大小的自动或命名设置,矩形,即屏幕的大小减去statusBar。

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);

这篇关于将TabBarController添加为视图的子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 13:45