iOS objective c 把uitabbar换成了一个button但是button没有交互?

iOS objective c replacing uitabbar with a button but button has no interaction?

我认为这种情况非常典型,但我无法让它发挥作用。这是我的视图关系:扩展的 UITabBarController (A) -> UINavigationController (B) -> 扩展的 UIViewController 作为根视图控制器 (C) -> 带有 UIButton (E) 的目标视图控制器 (D)。

最初显示的是根视图控制器,它是一个集合视图,然后推送到 D,在 D 的初始化期间,在 viewWillAppear 和 viewWillLayoutSubviews 中,我放置了代码来隐藏标签栏 A 并保持 B 的导航栏显示, 并将 D 的视图设置为新的框架高度,以确保它可以覆盖整个屏幕,然后将 UIButton E 框架布局到与选项卡 A 的框架完全一致。

结果是按钮 E 在上一个标签栏的位置正确显示,但它不响应任何手势或触摸事件。

下面是D的代码:

- (void)viewWillLayoutSubviews{
    [self.navigationController.tabBarController.tabBar setHidden:YES];
    [self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height + self.navigationController.tabBarController.tabBar.frame.size.height)];
    [_button setFrame:CGRectMake(0.0f, screenRect.size.height - buttonHeight - self.navigationController.navigationBar.frame.size.height - [UIApplication sharedApplication].statusBarFrame.size.height, screenRect.size.width, buttonHeight)];
    [self.view addSubview:_button];
    [self.view bringSubviewToFront:_button];
}

我试过使用

[self.view insertSubview:_button atIndex:0]

也一样,并检查了调试器中的视图层次结构,看起来都很好,除了没有触发交互事件。

感谢您的帮助!

youNextViewController.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:youNextViewController animated:YES];