我怎样才能使 UITabBar 离开屏幕并识别它通常所在位置的点击?

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

不使用 "hidesBottomBarWhenPushed"。

我试过向下设置 UITabBar 的动画,使 Y 与 self.view.bounds.frame.y 相同。在我的 viewController 中,我还有一个 tableView,它具有从 TableView 到 SuperView 的 Bottom 约束。称之为 self.constraintTableViewBottomToSuperViewBottom。当视图加载时,我设置减去标签栏的高度到这个约束。这种组合在视觉上是完美的。 tableView 是它应该的确切高度,并且在视图底部正常工作。问题是……UITabBar 所在的底部 44px 区域……不允许触摸事件。我可以点击那里的任何东西。我错过了什么我还需要在屏幕外设置动画(我应该提到我也在设置 UITabBarController 的 UITransition 视图的动画)以接收触摸?有人可以帮忙吗?

如果你问自己 "Why in the hell would you want to do this... why not just use hidesBottomBarWhenPushed... I'll include the reasoning below"。


我正在使用 ECSlidingViewController。我相信解决方案是我必须停止使用它,因为它的错误是一个问题,但我想看看我是否可以解决这个问题。

问题是,hidesBottomBarWhenPushed does not work with ECSlidingViewController and is a known issue。所以我不能使用 hideBottomBarWhenPushed,因为我使用的是 ECSlidingViewController。我还不想废弃 ECSlidingViewController,我想看看我是否可以找到解决方案。

我试过这段代码,效果很好。我在标签栏所在的 space 中与我的应用程序交互没有任何问题。

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

尝试一下...使用自定义动画隐藏标签栏后,使用系统调用隐藏标签栏:

[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;
}];

它也可能是您调用动画的地方。开始动画后,UIKit 中的某些东西可能会弄乱标签栏区域。例如,如果您从 -viewWillAppear: 调用开始动画。因此,请尝试稍微延迟您的动画,看看是否有帮助。

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;
    }];
});

注意我选择使用 GCD 延迟而不是 UIView 动画延迟。只是为了确保在延迟之前它不会弄乱标签栏。

另请注意,我并没有为这里的自动布局约束而烦恼。只是移动它。工作正常。保持隐藏状态。