我在 iOS 7.1 上试过我的应用程序,我发现标签栏背景有几次消失了。我能够找到他们;它发生在:
- 使用
hidesBottomBarWhenPushed = YES
推送放置在导航 Controller (即标签栏 Controller 内)内的 View Controller
- 呈现一个 View Controller 然后关闭它(即
MFMailComposeViewController
)
我创建了一个示例应用程序(使用标签栏模板 + 添加按钮来显示 View Controller ,以及一个 mapView 来判断栏是否消失),问题就在那里。
以下是我更改的示例应用程序的所有代码:
#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/