Search code examples
iosobjective-cuibuttonuitabbar

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


I believe this scenario would be very typical one but I cannot get it work. Here is my views relationship : an extended UITabBarController (A) -> UINavigationController (B) -> extended UIViewController as root view controller (C) -> target view controller (D) with a UIButton (E).

Initially, the root view controller, which is a collection view is showing, then push to D, during D's initialization, in viewWillAppear and viewWillLayoutSubviews , I put code to hide the tabbar A and keep the navigation bar of B showing, and set D's view to a new frame height to make sure it can cover the full screen, then layout the UIButton E frame to exactly the tabbar A's frame.

The result is that the button E is displaying properly, at the previous tabbar's position, but it does not response to any gesture or touchupinside events.

Below is the code of 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];
}

I tried using

[self.view insertSubview:_button atIndex:0]

too, and checked the view hierarchy in debugger, all LOOKS good except no interaction events fired.

Thanks for any help!


Solution

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