6

I have an app based on custom tabBar controller and now, since we have safe area layout, I want to change my app to fully utilise the iPhone X screen.

So I want to fix the issue of tabBar, which currently doesn't consider safe area.

I have gone through most of those solutions people are posting but those are mostly for UIViewController.

My current tabBar looks like this

Tab bar screenshot showing overlapping iPhone X bottom swipe indicator

I am using RDVTabBar for this and this tab bar is an instance of UIView and I am not using storyboard or xib, everything is done programmatically.

Current code to fix the issue

if (@available(iOS 11.0, *)) {
    UILayoutGuide *safe = self.view.safeAreaLayoutGuide;
    self.tabBar.translatesAutoresizingMaskIntoConstraints = NO;

    [NSLayoutConstraint activateConstraints:@[[safe.trailingAnchor constraintEqualToAnchor:self.tabBar.trailingAnchor],
                                              [self.tabBar.leadingAnchor constraintEqualToAnchor:safe.leadingAnchor],
                                              [safe.bottomAnchor constraintEqualToAnchor:self.tabBar.bottomAnchor]]];

    [self.tabBar addConstraint:[NSLayoutConstraint constraintWithItem:self.tabBar
                                                      attribute:NSLayoutAttributeHeight
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:nil
                                                      attribute: NSLayoutAttributeNotAnAttribute
                                                     multiplier:1
                                                       constant:45]];

}

But by this doesn't change anything

I have a workaround considering my current code structure and this works

CGRect frame = self.tabBar.frame;
frame.origin.y = frame.origin.y - 34;
frame.size.height = frame.size.height + 34;
self.tabBar.frame = frame;

But its not using safe area layout guides and, if future safe area heights change, then this won't work; so I am not willing to use this.

So how can I fix this issue using safe area layout guide just for this tabBar?

patridge
  • 26,385
  • 18
  • 89
  • 135
Paras Gorasiya
  • 1,295
  • 2
  • 13
  • 33

0 Answers0