iOS8 自定义UITabBar (使用popToViewController致使的UITabBarButton重叠的问题)

想看详细的,能够看这篇文章,有时候 在popToViewController 的时候 ,本来一开始被咱们移除的UITabbarButton会莫名其妙的再次加载到UITabBar上了,考虑到咱们一开始就在UITabBarController的- ViewDidLoad 方法里面移除了,以下面这样:iphone

//@interface MainTabBarController : UITabBarController

- (void)viewDidLoad {

    for (UIView *subView in self.tabBar.subviews) {
    
        [subView removeFromSuperview];
     }
     //自定义一些控件子视图
 }
复制代码

并且 -ViewDidLoad 此方法在生命周期里面只会走一次,因此咱们判定必定是在Apple 在 [super viewWillLayoutSubviews] 作了一些判断,因此咱们必需要在 [super viewWillLayoutSubviews] 以后再移除掉就好了ui

//@interface MainTabBarController : UITabBarController

- (void)viewWillLayoutSubviews {

    [super viewWillLayoutSubviews];

    for (UIView *subView in self.tabBar.subviews) {
    
        ![subView isKindOfClass:NSClassFromString(@"UITabBarButton")] ?: [subView removeFromSuperview];
    }
}
复制代码
相关文章
相关标签/搜索