美文网首页
iOS11 自定义tabbar遇到的问题,删除系统自带tabb

iOS11 自定义tabbar遇到的问题,删除系统自带tabb

作者: wodeph | 来源:发表于2017-11-13 11:37 被阅读0次

自定义tabber,就是创建自己的tabbar盖在系统的tabbar上面

//自定义tabbar

GJWTabBar   *customTabBar = [[GJWTabBar alloc]init];

customTabBar.frame=self.tabBar.bounds;

customTabBar.delegate=self;

[self.tabBar addSubview:customTabBar];

self.customTabBar= customTabBar;

// 删除系统自动生成的UITabBarButton

- (void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

// 删除系统自动生成的UITabBarButton

for(UIView *child in self.tabBar.subviews) {

if([child isKindOfClass:[UIControl  class]]) {

[child   removeFromSuperview];

}

}

}

可是当我运行时候,系统自带的按钮依然像盖在

上面,出现两个tabbar,之前的ios11以前都没有这个问题的。

后来发现在-(void)viewDidAppear:(BOOL)animated里面重新调用删除系统自带tabbar

就可以了。

以下没有删除掉的情况

方法二:隐藏自带的,创建一个view,来替代。

- (void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    self.tabBar.hidden = YES; //隐藏自带的tabBar

    for (UIView *child in self.tabBar.subviews) {

        if ([child isKindOfClass:[UIControl class]]) {

            child.hidden = YES;//隐藏自带的tabBarButton

        }

    }

}

注:不喜勿喷!!!

相关文章

网友评论

      本文标题: iOS11 自定义tabbar遇到的问题,删除系统自带tabb

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