其實(shí)重疊的原因是系統(tǒng)添加了自帶的UITabBarButton逸嘀,將其刪除即可
解決方法一:
在自定義的UITabBarController中添加以下代碼
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
for (UIView *subView in self.tabBar.subviews) {
// 刪除系統(tǒng)自帶的tabBarButton
![subView isKindOfClass:NSClassFromString(@"UITabBarButton")] ?: [subView removeFromSuperview];
}
}
解決方法二:
在自定義的NavigationController中遵循UINavigationController的代理
設(shè)置代理:
- (void)viewDidLoad{
[super viewDidLoad];
self.delegate = self;
}
實(shí)現(xiàn)代理:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
// 刪除系統(tǒng)自帶的tabBarButton
for (UIView *tabBar in self.tabBarController.tabBar.subviews) {
if ([tabBar isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[tabBar removeFromSuperview];
}
}
}
解決方法二:
在自定義的NavigationController中添加如下代碼:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeTabBarBtn) name:@"removeTabBarBtn" object:nil];
}
- (void)removeTabBarBtn {
for (UIView *tabBar in self.tabBarController.tabBar.subviews) {
if ([tabBar isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[tabBar removeFromSuperview];
}
}
}
-(void)dealloc {
[[NSNotificationCenter defaultCenter]removeObserver:self name:@"removeTabBarBtn" object:nil];
}
并在調(diào)用popTo或pop方法的viewController中發(fā)出通知:
[self.navigationController popToRootViewControllerAnimated:YES];
/// 或者
///[self.navigationController popViewControllerAnimated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:@"removeTabBarBtn" object:nil userInfo:nil];