如下代码是tabBarController收到一个通知后跳转到首页的一个逻辑,XLBaseNavigation 继承自UINavigationController,self集成自TabBarController。这里会出现一个问题
-
(void)goHome:(NSNotification *)notfication {
XLBaseNavigation *nav = self.childViewControllers[self.selectedIndex];
[nav popToRootViewControllerAnimated:YES];
self.tabBar.hidden = NO;self.selectbtn.selected = NO;
self.selectbtn = [self.barView viewWithTag:100];
self.selectbtn.selected = YES;
self.selectedIndex = self.selectbtn.tag-100;
}
N.gif
其实道理很简单,就是popToRootViewControllerAnimated执行动画是一段时间完成的一系列pop操作,可以理解成异步的,所以必须等pop动画里的代码执行完成才能让self.tabBar显示出来,或者直接不让popToRootViewControllerAnimated不做动画,就ok
-
(void)goHome:(NSNotification *)notfication {
XLBaseNavigation *nav = self.childViewControllers[self.selectedIndex];
[nav popToRootViewControllerAnimated:NO];
self.tabBar.hidden = NO;
self.selectbtn.selected = NO;self.selectbtn = [self.barView viewWithTag:100];
self.selectbtn.selected = YES;
self.selectedIndex = self.selectbtn.tag-100;
}
效果如下
Y.gif
网友评论