【发布时间】:2018-06-12 16:56:48
【问题描述】:
我从一开始就以编程方式构建了这个完整的应用程序。该项目是在旧的 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 启动屏幕,它使完整的应用程序可以运行 我已经进行了足够的研究,但无法找到解决方案。
【问题讨论】:
-
请更新您的 Xcode。我发布的答案是在 Xcode 9.4.1 中创建的。 Xcode 6 太旧了,无法与 iPhone X 一起使用
-
我的是 9.2。让我试试你的解决方案。
标签: uitabbarcontroller xcode9 iphone-x programmatically-created