我在加載啓動屏幕時啓動應用程序。然後我想加載一個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];
}
如果你在viewWillAppear中運行self.tabBarController.view.frame = [[self view] frame],它將工作,而你不必自己算出數字,因爲那時邊界和幀已被正確/完全計算。 – pulkitsinghal 2011-12-29 16:26:55
會更好回答:tabBarController.view.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);因爲寬度和高度根據用戶使用的每個設備而有所不同? – lakesh 2013-02-14 10:49:15