【问题标题】:How to have tabBar animate in after the view is fully pushed into view?视图完全推入视图后如何让 tabBar 动画?
【发布时间】:2013-04-07 12:44:54
【问题描述】:

我正在尝试模拟 TweetBot/NetBot 在从帐户操作的 tableView 推送之后为 tabBar 设置动画的方式。当视图被完全推送时,taBar 才会从底部动画。我尝试了各种隐藏/显示方法,但在“显示”部分似乎都失败了。

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

【问题讨论】:

    标签: iphone ios uitabbarcontroller show-hide


    【解决方案1】:

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

    【讨论】:

    • 好的,我在你回答之前使用了 NavController -> TabBarController。由于故事板让我这样做,并且一切正常,我认为没问题。你是说我需要使用普通的 VC 并滚动我自己的 Tabbarcontroller 吗?我可以将标签栏设置为不可见的动画,但是如果工作的话,之后显示它会很混乱。
    • Documentation about UINavigationController 声明:pushViewController:animated: "此对象不能是标签栏控制器的实例" initWithRootViewController: "此对象不能是UITabBarController 类的实例。” 无论如何,也许推动它可以工作,但我不知道这是否会导致一些不当行为。你确定你真的需要将它推入导航堆栈吗?也许您可以在需要时仅隐藏标签栏来获得相同的结果。顺便说一句,你试过我的动画代码了吗?
    • 决定换个方向,直到我弄明白为止。感谢您尝试帮助亚历山德罗 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    相关资源
    最近更新 更多