无法显示标签栏

时间:2017-12-14 09:31:14

标签: ios objective-c iphone uitabbarcontroller xcode9

我有一个应用程序我隐藏并在事件上显示tabbar,下面是我正在使用的方法,当我试图隐藏它时,它工作正常。但是,当我试图让它变得可见时,它不起作用。

-(void)setTabBarVisible:(BOOL)visible animated:(BOOL)animated completion:(void (^)(BOOL))completion {

  //  RootViewController* tabBarController = (RootViewController*)self.navigationController.parentViewController.parentViewController;
    UITabBarController *tabBarController = self.tabBarController;

    CGFloat duration = (animated)? 0.3 : 0.0;

    CGRect frame = tabBarController.tabBar.frame;
    CGFloat height = frame.size.height;
    CGFloat offsetY = (visible)? -height : height;


    CGRect playerFrame = player.view.frame;
    CGRect toolBarFrame = self.toolbar.frame;

    [UIView animateWithDuration:duration animations:^{

        CGRect fr = CGRectOffset(frame, 0, offsetY);
        tabBarController.tabBar.frame = fr;
        if((!visible && ![self toolBarOnBottom]) || visible) {
            self.toolbar.frame = CGRectOffset(toolBarFrame, 0, offsetY);
            [self.toolbar layoutIfNeeded];
        }

    } completion:completion];


}

我第二次调试代码时调用此方法使其可见,tabbar框架为零,我认为这是问题所在。我正在使用iOS 11 SDK在Xcode 9上测试它。我不确定安全区域是否与此有关。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

由于我想获得一个有效的解决方案,最终使用了这个,完美的自动布局和安全区域

Hide UINavBar and UITabBar at the same time with animation

相关问题