ios - 当状态恢复时 hidesBottomBarWhenPushed = YES 时,导航 Controller 不隐藏标签栏

标签 ios objective-c uikit

我在将 hidesBottomBarWhenPushed=YES 推送到位于 UITabBarController 中的 UINavigationController 中恢复 View Controller 的状态时遇到问题。

基本上 UINavigationController 堆栈已恢复并且正确的 Controller 出现在屏幕上,但是该 Controller 不遵守 hidesBottomBarWhenPushed。

我想到的唯一可行的 hack 是 viewDidAppear 上的快速选项卡开关,使 TabBar 消失,因为它应该在 hidesBottomBarWhenPushed 设置时发生:

- (void)_fixTabBarStateRestorationBug {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSInteger currentTab = (NSInteger)self.tabBarController.selectedIndex;
        self.tabBarController.selectedIndex = abs(currentTab - 1);
        self.tabBarController.selectedIndex = currentTab;
    });
}

最佳答案

这绝对是一个 iOS 错误。上面的解决方案对我来说不是开箱即用的,但是如果你把它放在标签栏 Controller 的 viewDidAppear 方法中就可以了:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    NSInteger currentTab = (NSInteger)self.tabBarController.selectedIndex;
    self.tabBarController.selectedIndex = abs(currentTab - 1);
    self.tabBarController.selectedIndex = currentTab;
});

如果您将它放在选项卡中 View Controller 的 View Controller viewDidAppear 中,您将创建一个无限循环。为此,请使用问题中提到的一次性标记方法。

关于ios - 当状态恢复时 hidesBottomBarWhenPushed = YES 时,导航 Controller 不隐藏标签栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23105057/

相关文章:

iphone - 获取 UITableView 部分的框架

ios - 当 shouldAutorotateToInterfaceOrientation 总是返回 NO 时发生了什么?

ios - NSFileManager:enumeratorAtURL: 返回一个不同形式的 URL 到 NSFileManager:URLForDirectory

objective-c - iOS 上事件监视器中的实时字节与实际内存

iphone - 使用条件语句以编程方式切换UIButton文本

cocoa-touch - UIWebView:当 "touch up"在链接之外时取消打开链接?

ios - Ionic 2 InAppBrowser 选项不起作用

ios - 删除 UISearchBar 中的清除按钮

iphone - iOS - 获取 Info.plist 文件

ios - UITableViewCell contentView inset on iPhone X