如何在视图完全推入视图后使用tabBar动画?

时间:2013-04-07 12:44:54

标签: iphone ios uitabbarcontroller show-hide

我试图模仿TweetBot / NetBot在从tableView of Accounts操作推送后激活tabBar的方式。完全按下视图后,taBar才会从底部进行动画制作。我尝试过各种各样的隐藏/显示方法,而且在“show”部分时似乎都失败了。

有没有人建议如何做到这一点?

1 个答案:

答案 0 :(得分:0)

首先,我假设您没有使用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;
   }];
}