美文网首页
解决返回TabbarController底部Tabbar上方上移

解决返回TabbarController底部Tabbar上方上移

作者: mrChan1234 | 来源:发表于2019-08-22 10:27 被阅读0次

经常我们会碰到这种需求,就是返回首页选中某一个tabbaritem,在自定义tabbar的时候,遇到这个奇葩的问题,返回首页选中第一个的时候,self.view整体被上移动了49pt,而且这49pt还是黑色的,通过小面包看层级发现这个view的类名叫做UITransitionView,这里采用的本办法就是讲这个view的背景色设置成当前显示控制器的背景色,然后强制让self.view调用layoutsubviews再让它布局一遍,代码如下:

 SendNotify(@"backToHome", nil);
            [self.navigationController popToRootViewControllerAnimated:YES];

- (void)setSelectedIndex:(NSInteger)index {
    DTTabBarController *tabBarController = (DTTabBarController *)kAppWindow.rootViewController;
    if (tabBarController) {
        tabBarController.selectedIndex = index;
    }
}

 @objc func backHome() {
        for subView in self.view.subviews {
            if subView.className().contains("UITransitionView", compareOption: NSString.CompareOptions.caseInsensitive) {
                subView.backgroundColor = UIColor.kColor243
                view.layoutSubviews();
                continue
            }
        }
}
    
    // MARK: - memory management
    deinit {
        NotificationCenter.default.removeObserver(self)
    }

相关文章

网友评论

      本文标题:解决返回TabbarController底部Tabbar上方上移

      本文链接:https://www.haomeiwen.com/subject/dywgsctx.html