How can I animate a UITabBar off the screen and recognize taps where it would normally reside?

644 views Asked by At

No using "hidesBottomBarWhenPushed".

I've tried animating the UITabBar down so that the Y is the same as the self.view.bounds.frame.y. In my viewController I also have a tableView that has a Bottom constraint from the TableView to the SuperView. Call it self.constraintTableViewBottomToSuperViewBottom. I'm setting subtracting to this constraint the height of the tab bar when the views loads. This in combination is visually perfect. The tableView is the exact height it should be, and works properly at the bottom of the view. The problem is... that bottom 44px area where the UITabBar was... is not allowing touch events. I can tap anything there. What am I missing that I also need to animate off the screen (I should mention I'm also animating off the UITabBarController's UITransition view) to receive touches? Can anyone help?

If you're asking yourself "Why in the hell would you want to do this... why not just use hidesBottomBarWhenPushed... I'll include the reasoning below".


I'm using ECSlidingViewController. I believe the solution is I have to stop using this because it's bug is a showstopper, but I want to see if I can hack my way around the issue.

The problem is, hidesBottomBarWhenPushed does not work with ECSlidingViewController and is a known issue. So I cannot use hideBottomBarWhenPushed, because I'm using ECSlidingViewController. I don't want to scrap ECSlidingViewController just yet, I want to see if I can hack my way around a solution.

1

There are 1 answers

1
Dave Batton On BEST ANSWER

I tried this code, and it worked perfectly. I didn't have any problem interacting with my app in the space where the tab bar had been.

[UIView animateWithDuration:0.3f animations:^{
    self.tabBarController.tabBar.frame = CGRectOffset(self.tabBarController.tabBar.frame, 0.0f, 49.0f);
}];

Something to try... After you hide the tab bar with your custom animation, hide the tab bar with the system call:

[UIView animateWithDuration:0.3f animations:^{
    self.tabBarController.tabBar.frame = CGRectOffset(self.tabBarController.tabBar.frame, 0.0f, self.tabBarController.tabBar.frame.size.height);
}
completion:^(BOOL finished) {
    self.tabBarController.tabBar.hidden = YES;
}];

It may also be where you're calling your animation. It's possible something in UIKit is messing with the tab bar area after you start animating it. For example, if you started the animation right from the -viewWillAppear: call. So try delaying your animation a bit to see if that helps.

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [UIView animateWithDuration:0.3f animations:^{
        self.tabBarController.tabBar.frame = CGRectOffset(self.tabBarController.tabBar.frame, 0.0f, self.tabBarController.tabBar.frame.size.height);
    }
    completion:^(BOOL finished) {
        self.tabBarController.tabBar.hidden = YES;
    }];
});

Notice I chose to use a GCD delay rather than the UIView animation delay. Just to make sure it doesn't mess with the tab bar until after the delay.

Also notice I'm not bothering with auto layout constraints here. Just moving it. Works fine. Stays hidden.