【发布时间】:2013-04-07 12:44:54
【问题描述】:
我正在尝试模拟 TweetBot/NetBot 在从帐户操作的 tableView 推送之后为 tabBar 设置动画的方式。当视图被完全推送时,taBar 才会从底部动画。我尝试了各种隐藏/显示方法,但在“显示”部分似乎都失败了。
有人对如何做到这一点有建议吗?
【问题讨论】:
标签: iphone ios uitabbarcontroller show-hide
我正在尝试模拟 TweetBot/NetBot 在从帐户操作的 tableView 推送之后为 tabBar 设置动画的方式。当视图被完全推送时,taBar 才会从底部动画。我尝试了各种隐藏/显示方法,但在“显示”部分似乎都失败了。
有人对如何做到这一点有建议吗?
【问题讨论】:
标签: iphone ios uitabbarcontroller show-hide
首先,我假设您没有使用 UITabViewController,因为它不能被推入 UINavigationController 堆栈,所以我认为您使用的是嵌入在 UIViewController 中的独立 UITabBar。这个假设对吗?
用这段代码试试(我没试过)。
- (void)viewDidAppear {
[super viewDidAppear];
// Calls showTabBar method after SOME_DELAY. You can also call directly [self showTabBar] if you want zero delay.
[self performSelector:@selector(showTabBar) afterDelay:SOME_DELAY];
}
- (void)showTabBar {
// Before the animation begins, your UITabBar must be outside the view controller's view frame.
CGRect tabBarFrame = CGRectMake(0,
CGRectGetHeight(self.view.bounds),
CGRectGetWidth(self.view.bounds),
CGRectGetHeight(self.tabBar.frame);
self.tabBar.frame = tabBarFrame;
// Let's start with the animation, setting a new frame for tab bar inside an animation block
[UIView animateWithDuration:ANIMATION_DURATION animations:^{
// Change origin Y. It assumes that the height of self.tabBar is right, otherwise put the height you want instead of CGRectGetHeight(self.tabBar.frame).
tabBarFrame.origin.y = CGRectGetHeight(self.view.bounds) - CGRectGetHeight(self.tabBar.frame);
self.tabBar.frame = tabBarFrame;
}];
}
【讨论】:
pushViewController:animated: "此对象不能是标签栏控制器的实例" initWithRootViewController: "此对象不能是UITabBarController 类的实例。” 无论如何,也许推动它可以工作,但我不知道这是否会导致一些不当行为。你确定你真的需要将它推入导航堆栈吗?也许您可以在需要时仅隐藏标签栏来获得相同的结果。顺便说一句,你试过我的动画代码了吗?