呈现和关闭视图控制器后,iOS 7.1上的选项卡栏背景丢失 [英] Tab bar background is missing on iOS 7.1 after presenting and dismissing a view controller

查看:101
本文介绍了呈现和关闭视图控制器后,iOS 7.1上的选项卡栏背景丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 7.1上尝试了我的应用程序,但发现标签栏背景在某些情况下会消失.我能够找到他们.它发生在以下情况:

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:

  • 使用hidesBottomBarWhenPushed = YES将放置在导航控制器(即标签栏控制器内部)中的视图控制器推入
  • 展示一个视图控制器,然后关闭它(即MFMailComposeViewController)
  • 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)

我已经创建了一个示例应用程序(使用标签栏模板+添加的按钮来显示视图控制器,并使用mapView来判断该栏是否消失了),并且问题出在这里.

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.

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

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.

现在,重要的是:这似乎不会影响iPhone 5,也不会影响模拟器.问题出在iPhone 4和iPod Touch(写这篇文章时是上一代)上.

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!

更新:我找到了一种解决方法.请在下面查看我的答案.

推荐答案

已解决!

因此,在进行了一些调查(和头痛)之后,我发现有一个简单的修复方法.只需像这样切换translucent属性:

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;


现在,何时执行此操作,每种情况有几个位置:

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


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)呈现一个视图控制器,然后将其关闭:
在这种情况下,在关闭动画期间选项卡栏背景已经消失了.您可以在分别显示的每个viewController中执行此操作,或者,如果您已将UITabBarController子类化(如我所拥有的),则可以将其添加到其viewWillAppear方法中.请注意,立即致电修复程序无济于事(我已经尝试过);这就是为什么我使用dispatch_after GCD函数的原因:


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


我知道这不是最干净的方法,但这显然是苹果方面的错误,而且可能会在我们身边待一段时间(我认为不会有任何iOS 7.2,因此我们很可能会坚持使用直到iOS 8发布).


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).

这篇关于呈现和关闭视图控制器后,iOS 7.1上的选项卡栏背景丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆