iOS自定义TabBar使用popToRootViewControllerAnimated重叠问题解决
2016-04-26 21:01
477 查看
先看下现象吧,如下图:
不仅仅重叠了,而且还把图标给覆盖了。
很郁闷。
折腾了很久,终于找到解决办法了。
解决方法一:
在自定也的NavigationController中添加如下代码:
并且在调用popToRootViewControllerAnimated方法的viewController中发出通知:
解决方法二:
(该方法更为简单)苹果强大就强大在这里,他们已经预想到了。
所以方法就是:遵循UINavigationController的代理,用代理方法解决该Bug,代码如下:
设置代理:
实现代理方法:
最后运行,完美解决。用王祖蓝常说的一句话:完美 !
不仅仅重叠了,而且还把图标给覆盖了。
很郁闷。
折腾了很久,终于找到解决办法了。
解决方法一:
在自定也的NavigationController中添加如下代码:
- (void)viewDidLoad{ [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeTabBarBtn) name:@"removeTabBarBtn" object:nil]; } - (void)removeTabBarBtn { // NSArray *tSubviews = self.tabBarController.tabBar.subviews; // for (int i = 0; i < tSubviews.count; i++) { // Class parentVCClass = [tSubviews[i] class]; // NSString *className = NSStringFromClass(parentVCClass); // ALog(@"%d---%@",i, className); // // } 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]; }
并且在调用popToRootViewControllerAnimated方法的viewController中发出通知:
[self.navigationController popToRootViewControllerAnimated:NO]; [[NSNotificationCenter defaultCenter] postNotificationName:@"removeTabBarBtn" object:nil userInfo:nil];
解决方法二:
(该方法更为简单)苹果强大就强大在这里,他们已经预想到了。
所以方法就是:遵循UINavigationController的代理,用代理方法解决该Bug,代码如下:
设置代理:
- (void)viewDidLoad{ [super viewDidLoad]; self.delegate = self; }
实现代理方法:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // 删除系统自带的tabBarButton for (UIView *tabBar in self.tabBarController.tabBar.subviews) { if ([tabBar isKindOfClass:NSClassFromString(@"UITabBarButton")]) { [tabBar removeFromSuperview]; } } }
最后运行,完美解决。用王祖蓝常说的一句话:完美 !
相关文章推荐
- ios高级课之---数据处理之文件读写1
- iOS:在使用Cocoapods安装shareSDK时出现的link路径错误
- iOS 写入文件保存数据的方式
- iOS开发--多线程编程(二)NSThread买票
- iOS开发点滴-添加阴影效果
- iOS LLDB调试精解
- iOS8新特性之交互式通知
- iOS dSYM文件结构剖析(上)
- iOS Crash文件的解析(一)
- iOS单元测试GHUnit + OCMock(使用cocoapods版)
- iOS基础:获取资源文件的方法
- iOS开发-你真的会用SDWebImage?(转发)
- IOS+openCV在Xcode的入门开发
- iOS实现左右循环滑动ScrollVIew
- IOS实现自动循环滚动广告--ScrollView的优化和封装
- iOS dataFormatter 8小时 误差
- ios runtime void method_exchangeImplementations
- iOS运行时与method swizzling
- iOS运行时与method swizzling
- [ios]CGContext 函数说明