UITabbar无故消失问题

问题现场是这样的
切换tab,tabvc内嵌navvc,三个tab其中两个是系统UIVC的,tabbar不隐藏,而有一个自定义的,会隐藏。

frame #0: 0x0000000101893297 palfish_class`-[PFBTabBar setHidden:](self=0x00007fb35822a370, _cmd="setHidden:", hidden=YES) at PFBTabBar.m:135:5
    frame #1: 0x00000001285d4f7e UIKitCore`-[UITabBarController animationDidStop:finished:context:] + 157
    frame #2: 0x00000001285d5717 UIKitCore`-[UITabBarController _hideBarWithTransition:isExplicit:duration:] + 1410
    frame #3: 0x0000000128610cf3 UIKitCore`-[UINavigationController _hideOrShowBottomBarIfNeededWithTransition:] + 958
    frame #4: 0x00000001285d9d76 UIKitCore`-[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 3372
    frame #5: 0x00000001285d3994 UIKitCore`-[UITabBarController _setSelectedViewController:] + 426
    frame #6: 0x00000001285d3730 UIKitCore`-[UITabBarController setSelectedIndex:] + 129

经过分析发现,是因为自定义的TKVC,的init方法是这样的

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

而初始化时的tabbar

[[TKNavigationController alloc] initWithRootViewController:[TKViewController new]];

因为是设置rootVC,起初没往hidesBottomBarWhenPushed上想,没认为是push。但定位问题后,发现就是它导致的。initWithRootViewController其实也是push,将参数vc作为栈底元素。

Discussion
This is a convenience method for initializing the receiver and pushing a root view controller 
onto the navigation stack. Every navigation stack must have at least one view 
controller to act as the root.

Parameters
The view controller that resides at the bottom of the navigation stack. This object 
cannot be an instance of the UITabBarController class.

Returns
The initialized navigation controller object or `nil` if there was a problem initializing the object.

你可能感兴趣的:(UITabbar无故消失问题)