我在将 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/