20

I've tried my app on iOS 7.1 and I found that the tab bar background disappears on a few occasions. I was able to track them down; it happens when:

  • pushing a view controller placed inside navigation controller (that is inside tab bar controller) with hidesBottomBarWhenPushed = YES
  • presenting a view controller and then dismissing it (i.e. the MFMailComposeViewController)

I've created a sample app (used the tab bar template + added button to display the view controller, and a mapView to be able to tell if the bar disappeared), and the issue is there.

enter image description here

Here is all the code for the sample app that I changed:

#import "FirstViewController.h"

@import MessageUI;

@interface FirstViewController () <MFMailComposeViewControllerDelegate>

@end

@implementation FirstViewController

- (IBAction)presentVCButtonPressed:(id)sender {
    if ([MFMailComposeViewController canSendMail]) {

        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        mailer.mailComposeDelegate = self;
        [mailer setSubject:@"Feedback for Routie"];
        [mailer setToRecipients:@[@"support@routieapp.com"]];
        [self presentViewController:mailer animated:YES completion:nil];
    }
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

Here you can download the whole sample project.

Now, important thing: this seems not to affect iPhone 5, nor the simulator. The problem is on iPhone 4 and iPod Touch (last generation as of writing this post).

Does any of you have the same problem? Were you able to fix it? Thanks!

Update: I found a workaround. See my answer below.

Lukas Petr
  • 1,513
  • 16
  • 19
  • I'm experiencing the same issue here. Were you able to fix it? And don't you have this another issue also? http://stackoverflow.com/questions/22320964/ios-7-1-uibuttons-selected-state-not-working – Pei Mar 12 '14 at 02:23
  • yes, I was :). I am going to write the answer right now. Regarding the other issue: no, I don't have it. – Lukas Petr Mar 12 '14 at 09:42
  • 1
    Thanks for providing your solution. This bug is particularly tricky since it only happens on some devices (i.e. iPhone4). I am wondering why there is not more information available on the internet, I only found this SO thread after some intense googling... – jbandi Sep 06 '14 at 09:52

3 Answers3

23

Fix found!

So after some investigating (and headache), I found out that there is a simple fix. Just toggle the translucent property, like this:

tabBar.translucent = NO;
tabBar.translucent = YES;


Now as for when to do this, there are several places for each case:

1) pushing viewController with hidesBottomBarWhenPushed = YES
The bar background disappears right after the pop animation finishes, so add the fix to the viewDidAppear: method of the viewController that presented it:

- (void)viewDidAppear:(BOOL)animated {
    self.navigationController.tabBarController.tabBar.translucent = NO;
    self.navigationController.tabBarController.tabBar.translucent = YES;
    ...
}


2) Presenting a view controller and then dismissing it:
In this case, the tab bar background is already gone during the dismiss animation. You can either do it in each viewController that you present separately, or, if you have subclassed UITabBarController (like I have), you can add it into its viewWillAppear method. Just be aware that calling the fix right away won't help (I've tried); that's why I used the dispatch_after GCD function:

- (void)viewWillAppear:(BOOL)animated {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.tabBar.translucent = NO;
        self.tabBar.translucent = YES;
    });
    ...
}


I know this is not the cleanest way, but it's clearly bug on Apple's side, and it's likely to stay with us for a while (I assume there won't be any iOS 7.2, so we'll most likely be stuck with this until iOS 8 comes out).

Lukas Petr
  • 1,513
  • 16
  • 19
  • 1
    Another place to do the toggle is in a dismiss completion handler:[self.navigationController dismissViewControllerAnimated:YES completion:^(void){ UINavigationController *delNC = self.navigationController; delNC.tabBarController.tabBar.translucent = NO; delNC.tabBarController.tabBar.translucent = YES; }]; – earnshavian Mar 15 '14 at 09:16
  • 1
    Thanks. This crude workaround helped me with an iOS 8.0 issue where the tabBar didn't overlap anymore after a custom pop transition. However, I had to insert a `[tabBarController.view layoutSubviews]` in between the two lines. Also, this only works when `extendedLayoutIncludesOpaqueBars` is not set for the tabBar. – Ortwin Gentz Sep 12 '14 at 17:03
  • Also, I noticed that the `-layoutSubviews` affected the `contentOffset` of my `UITableView` so the tableView scrolled for about half a row. To fix this I saved the contentOffset and re-applied it after the `-layoutSubviews`. A workaround for the workaround! – Ortwin Gentz Nov 20 '15 at 13:51
  • 1
    Unbelievable but this bug still exists in iOS 11.2. – Ortwin Gentz Nov 20 '17 at 16:58
0

It's been a while, so I'll re-iterate the issue. iOS 7 (on Device) Tab Bar becomes completely see-through on device, but works fine on Simulator. Appears to happen after hitting Back from a detail page that has hidesBottomBarWhenPushed enabled.

Setting the Tab Bar Controller > Tab Bar > Background to White Color in the Storyboard fixed it for me. This fix keeps the translucency intact.

For some reason, toggling tabBar.translucent off and on again in ViewDidAppear did not work for me.

Using Xcode 6.3.1 with Swift.

Robert Chen
  • 5,179
  • 3
  • 34
  • 21
-1

Go in your Main.storyboard and select your MKMapView to highlighted it (cf. in Navigator area you can select « Map View »). Then look carefully where is the bottom "white square": move it up the bottom bar! In the size inspector, you can check where you place the « anchor » or view origin for this view (cf. top-left hand side in your project). This explains why it’s ok for iphone 5 which has a bigger height screen.

objM
  • 60
  • 1
  • 6
  • thanks for your answer, but the position of the tab bar is not the problem. Take a better look at the screenshot in my question: only the background is missing, the tab bar items are still there and it's still possible to change selected tab. Regarding the size: latest iPod Touch also has 4", so it's screen-size independent. – Lukas Petr Mar 11 '14 at 22:44