我从一开始就以编程方式完成了这个完整的应用程序构建。该项目是在一个旧的Xcode上启动的,可能是Xcode 6.我目前正在构建Xcode 6.我的项目有Objective-C和Swift文件相互通信。我遇到的问题是因为它是以编程方式构建的,我不能只是进入故事板并设置使用安全区域布局。
Xcode 9.2上的我的标签栏图像变得疯狂,还有导航栏。我想修复图像以及标签栏的高度。
以下是AppDelegate中用于添加tabbarcontroller的代码。
- (void)setupView {
UIViewController *firstViewController = [[UIViewController alloc]init];
firstViewController.view.backgroundColor = UIColor.redColor;
firstViewController.title = @"First View";
firstViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
UIViewController *secondViewController = [[UIViewController alloc]init];
secondViewController.view.backgroundColor = UIColor.blueColor;
secondViewController.title = @"Second View";
secondViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
UIViewController *thirdViewController = [[UIViewController alloc]init];
thirdViewController.view.backgroundColor = UIColor.purpleColor;
thirdViewController.title = @"Third View";
thirdViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemRecents tag:2];
UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:thirdViewController];
UIViewController *fourthViewController = [[UIViewController alloc]init];
fourthViewController.view.backgroundColor = UIColor.greenColor;
fourthViewController.title = @"Fourth View";
fourthViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:2];
UINavigationController *fourthNavController = [[UINavigationController alloc]initWithRootViewController:fourthViewController];
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
[tabBarController.tabBar invalidateIntrinsicContentSize];
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, fourthNavController, nil];
tabBarController.delegate = self;
[tabBarController.view setNeedsLayout];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
}
我添加了iPhone X启动画面,这使得完整的应用程序可以使用 我已经研究了足够但没有找到解决方案。
答案 0 :(得分:0)
您显然错过了这一行[[tabBarController view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
[tabBarController.tabBar invalidateIntrinsicContentSize];
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, fourthNavController, nil];
/* Enter this line */
[[tabBarController view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
tabBarController.delegate = self;
[tabBarController.view setNeedsLayout];
我尝试了您的代码并获得了结果:
这是屏幕截图: