添加一个TabBarController作为视图的子视图(Adding a TabBarContro

2019-08-02 12:01发布

我加载启动画面我的应用程序启动时。 然后我想加载一个TabBarController,它的ViewControllers。 然而,我的TabBarController窗不能扩展到屏幕大小。

在底部的TabBar的大概3/4是被截断,并有一个苗条的状态栏下方的屏幕顶部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];
}

Answer 1:

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

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

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

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

  4. 在XIB设置文件的所有者是Test1ViewController

  5. 连接tbc中文件的所有者IBOutlet中标签栏控制器的XIB。

  6. 连接view中文件的所有者IBOutlet中在厦门国际银行视图。

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

     Test1ViewController *tabBarViewController; 
  8. 合成tabBarViewControllerSplashViewController.m

  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. 最后,我也不得不改变finishedFading在方法SplashViewController.m到阿尔法设置为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]; } 

我希望这有帮助。



Answer 2:

我终于找到成才工程。 代替:

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

要么

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

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

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


文章来源: Adding a TabBarController as the Subview of a View