1

我正在尝试做一个类似于照片应用程序的 UI,当您进入隐藏标签栏以显示工具栏的选择模式时。

我在 UINavigationController 中有我的视图控制器,在 UITabBarController 中有导航控制器。

我之前有其他策略,但我正在努力让它在 iPhone X 及其底部安全边际上发挥作用。

4

2 回答 2

0

如果我根据您对 Photos App 的描述做出正确的假设,我想您可能会对从Photos App TabBar转到Photos App Toolbar时应用程序在幕后所做的事情感到困惑。

这是两个不同的 ViewController,第二个只显示工具栏和hidesBottomBarWhenPushed = trueinit 中的设置。setToolbarItems(toolbarItems: [UIBarButtonItem]?, animated: Bool)您可以通过在第二个 ViewController 中设置来使用 NavigationController 提供的工具栏。这会正确调整视图中工具栏的大小,以适应 iPhoneX 上的底部控件。

如果您必须在同一个 ViewController 中管理工具栏和 TabBar 可见性,根据我的测试,您需要在 UIView 容器中手动添加/管理工具栏,以在所有设备上获得正确的大小。所以视图层次结构是 ViewController.view -> toolbarContainer View -> Toolbar。

于 2017-10-10T20:59:15.693 回答
0

对于 iPhone X,标签栏高度与 iPhone 8 不同,您需要跟踪

static CGFloat tabBarMaxHeight = 0;

- (void)setToolbarHidden:(BOOL)hidden {
    [self.navigationController setToolbarHidden:hidden animated:NO];
    CGRect frame = self.tabBarController.tabBar.frame;
    tabBarMaxHeight = MAX(tabBarMaxHeight, CGRectGetHeight(frame));
    frame.size.height = hidden ? tabBarMaxHeight : 0;
    self.tabBarController.tabBar.frame = frame;
    self.tabBarController.tabBar.hidden = !hidden;

    //! reset tab bar item title to prevent text style compacted
    for (UITabBarItem *obj in self.tabBarController.tabBar.items) {
         NSString *title = obj.title;
         obj.title = @"";
         obj.title = title;
    }
 }
于 2018-03-20T04:43:58.750 回答