ios - 显示和关闭 View Controller 后,iOS 7.1 上的标签栏背景丢失

标签 ios uitabbar ios7.1

我在 iOS 7.1 上试过我的应用程序,我发现标签栏背景有几次消失了。我能够找到他们;它发生在:

  • 使用 hidesBottomBarWhenPushed = YES
  • 推送放置在导航 Controller (即标签栏 Controller 内)内的 View Controller
  • 呈现一个 View Controller 然后关闭它(即 MFMailComposeViewController)

我创建了一个示例应用程序(使用标签栏模板 + 添加按钮来显示 View Controller ,以及一个 mapView 来判断栏是否消失),问题就在那里。

enter image description here

以下是我更改的示例应用程序的所有代码:

#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

在这里你可以下载整个sample project .

现在,重要的是:这似乎不会影响 iPhone 5 或模拟器。问题出在 iPhone 4 和 iPod Touch(撰写本文时的最后一代)。

你们有遇到同样的问题吗?你能修好它吗? 谢谢!

更新:我找到了解决方法。请参阅下面我的回答。

最佳答案

找到修复!

经过一些调查(和头痛),我发现有一个简单的修复方法。只需切换 translucent 属性,如下所示:

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


现在至于何时执行此操作,每种情况都有几个地方:

1) 使用 hidesBottomBarWhenPushed = YES
push viewController 弹出动画结束后条形背景立即消失,因此将修复添加到 viewController 的 viewDidAppear: 方法呈现它:

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


2) 呈现一个 View Controller 然后关闭它:
在这种情况下,标签栏背景在关闭动画期间已经消失。您可以在单独呈现的每个 viewController 中执行此操作,或者,如果您有 UITabBarController 的子类(就像我一样),您可以将它添加到它的 viewWillAppear 方法中。请注意,立即调用修复程序无济于事(我试过);这就是我使用 dispatch_after GCD 函数的原因:

- (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;
    });
    ...
}


我知道这不是最干净的方法,但它显然是 Apple 方面的错误,它可能会在我们身边停留一段时间(我假设不会有任何 iOS 7.2,所以我们很可能会一直坚持下去,直到iOS 8 发布)。

关于ios - 显示和关闭 View Controller 后,iOS 7.1 上的标签栏背景丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22327646/

相关文章:

ios - UITabBarController 选项卡栏项目标题在 Xib 中不可见

ios - 自 ios7.1 以来的随机崩溃与 NSString(NSExtendedStringDrawing) drawWithRect :options:attributes:context

ios - 如何存储从reverseGeocodeLocation()方法(异步任务)检索的数据(到全局变量中)?

ios - 如何以编程方式更改 tabbarItem 的图像

ios - 在 Swift 中更改 UITabBar selectedItem

ios8 - BLE 在将数据从 iOS 7.1 发送到 iOS 8 时花费了太多时间

html - 静态谷歌地图在 iOS7.1 上不显示

ios - 想知道如何知道仪器时间分析器中的符号,并且仅在 Xcode 中显示地址

ios - 登录 iOS 应用程序和使用 Rails 设计后的 session 保留

ios - 应用内购买实现