Space Behind TabBar Unrecognizable

60 views Asked by At

In my app, there exist a scenario where I hide the bottom TabBar by [self.tabBarController.tabBar setHidden:YES] and later add a UIView containing UIButtons in the vacated area at the bottom of the view.

The area where the TabBar was will not respond to touch events so I can't select any of the buttons in the UIView.

I've done research on here and this question has been around for awhile but the old answers don't seem to work anymore. [self setNeeds Display] and self.tabBarController.tabBar.translucent = YES, do not work anymore as you still can't press the UIButtons. On a side note, I created my UIView with UIButtons in storyboards and put a bottom constraint to the superview. Please provide an answer known to work for iOS 9 and 10.

2

There are 2 answers

0
soumil On

I created a test project to check the functionality that you want.

class ViewController: UIViewController {

@IBOutlet weak var testButton: UIButton!
override func viewDidLoad() {
    super.viewDidLoad()
    testButton.addTarget(self, action: #selector(tapped), for: .touchUpInside)
    self.tabBarController?.tabBar.isHidden = true

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func tapped(_ sender:UIButton){
    print("Tapped")
}

}

As per your requirement, i created a uiview containing a UIButton as a subview and created a outlet for the button. As, i tab on on the button the action - tapped is triggered.

0
An Kit On

I created a project according to question. It's work fine. Please try this.

- (void)viewDidLoad {
[super viewDidLoad];
[self.tabBarController.tabBar setHidden:YES];

UIView *view = [[UIView alloc]initWithFrame:self.tabBarController.tabBar.frame];
[self.view addSubview:view];
view.backgroundColor = [UIColor redColor];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100,view.frame.size.height)];
[view addSubview:btn];
[btn setTitle:@"clicked me " forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnclicked:) forControlEvents:UIControlEventTouchDown];
}

-(void)btnclicked:(UIButton *)sender{ NSLog(@"button clicked event."); }