(使用popToViewController导致的UITabBarButton重叠的问题)
在iOS8 中允许动态添加tabbaritem,自定义的tabbar会出现重叠的情况,原本viewDidLoad()中已经移除的UITabBarButton再次出现。
解决:在自定义的BaseViewController的viewWillLayoutSubViews()方法里去移除UITabBarButton
// MARK: - Swift移除UITabBarButton
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
//print("viewWillLayoutSubviews:\(self.tabBarController?.tabBar.subviews)")
let aClass:AnyClass = NSClassFromString("UITabBarButton")!
guard let views = self.tabBarController?.tabBar.subviews else { return }
for view in views {
if view.isKind(of: aClass) {
view.removeFromSuperview()
}
}
}
#pragma mark - OC移除UITabBarButton
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
// tabBar移除UITabBarButton
for (UIView *subView in self.tabBar.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[subView removeFromSuperview];
}
}
}