【问题标题】:StatusBar is on top of navigationBar after MailComposer is dismissed关闭 MailComposer 后,状态栏位于导航栏的顶部
【发布时间】:2013-04-05 14:27:17
【问题描述】:

问题:在我将MFMailComposerViewController 显示为模态视图并将其关闭后,我的状态栏出现在navigationBar 的顶部。

-(IBAction)openMail:(id)sender
{
    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
    mc.mailComposeDelegate = self;

    [mc setSubject:emailTitle];
    [mc setMessageBody:messageBody isHTML:YES];
    [mc setToRecipients:toRecipents];
    [mc.navigationItem.leftBarButtonItem setTintColor:[UIColor colorWithRed:144/255.0f green:5/255.0f blue:5/255.0f alpha:1.0f]];
    [self presentViewController:mc animated:YES completion:NULL];
}


- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
    case MFMailComposeResultCancelled:
        NSLog(@"Mail cancelled");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"Mail saved");
        break;
    case MFMailComposeResultSent:
        NSLog(@"Mail sent");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Mail sent failure: %@", [error localizedDescription]);
        break;
    default:
        break;
}
// Reset background image for navigation bars
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationBar.png"] forBarMetrics:UIBarMetricsDefault];
NSLog(@"%@",[GGStackPanel printFrameParams:self.view]);
// Close the Mail Interface
GGAppDelegate * appDel = [[UIApplication sharedApplication] delegate];

HHTabListController * contr = (HHTabListController*)appDel.viewController;
[contr setWantsFullScreenLayout:NO];
NSLog(@"%i",[contr wantsFullScreenLayout]);
[self dismissViewControllerAnimated:YES completion:NULL];

}

Stackoverflow 上有几个类似的问题,但那里建议的解决方案都不适合我。 我已经试过了:

status bar and Navigation bar problem after dismissed modal view

http://developer.appcelerator.com/question/120577/nav-bar-appears-underneath-status-bar

我尝试从 AppDelegate 呈现和关闭,没有帮助。

更改视图框架或导航栏框架有效,但我必须对我的应用程序中的所有其他视图执行相同的操作(其中有很多)。这将使我的整个应用程序依赖于这个小错误。

截图

关闭 MailComposer 后:

【问题讨论】:

  • 可以发截图吗?
  • MailComposer 是否全屏显示?
  • 我不这么认为。我检查了 self.wantsFullScreenLayout 的值,它是 NO。我尝试使用 self.wantsFullScreenLayout,甚至尝试更改 appDelegate.viewController 和 MailComposer 的 WantsFullScreenLayout 属性 --> 没有变化。
  • 您的主 ViewController 的布局逻辑似乎不正确。什么是“HHTabListController”?
  • 我使用 HHTabListController 作为超级 viewController。我想要一个垂直的 tabBar,就像 Facebook 应用一样。所以我发现its close implementation here 我想也许如果我将 hhTabListController 的 wantFullScreenLayout 设置为 NO 可以解决问题,但显然它没有。

标签: ios objective-c user-interface uinavigationbar statusbar


【解决方案1】:

wantsFullScreenLayout 是一个复杂且不相关的东西。所有视图控制器都需要嵌入到“布局”视图控制器(Apples UINavigationController,Apple 的 UITabBarController)中,或者完全实现“我应该有多大,我应该在哪里定位?”的复杂逻辑。自己。

Apple 在 iOS 1.0 中决定您看到的 iPhone 主视图不会从 0,0 开始。包含它的 Window 从 (0,0) 开始,但它与状态栏重叠。

我认为这是他们后悔的决定,在当时是有道理的,但从长远来看,它会引起很多错误。

最终效果是:

  1. UINavigationController 和 UITabBarController 具有特殊的(未记录的)内部代码,使其看起来好像 (0,0) 是左上角 - 它们强制调整大小/重新定位您添加到其中的任何 UIViewController
  2. ...如果您不使用其中一个作为主控制器,则必须自己重新实现该逻辑。如果您使用的是第 3 方 UIViewController 实例,则逻辑通常会错误实现或丢失。
  3. ...您可以通过重新定位 UIViewController.view(其根视图)在运行时自行修复此问题,例如通过这个:

(代码)

UIViewController* rootController = // in this case HHTabController?
UIView* rootView = rootController.view;
CGRect frame = rootView.frame;
CGPoint oldOrigin = frame.origin;
CGPoint newOrigin = // calculate this, according to Apple docs.
// in your current case, it should be: CGPointMake( 0, 20 );
frame.origin = newOrigin;
frame.size = CGSizeMake( frame.size.width - (newOrigin.x - oldOrigin.x), frame.size.height - (newOrigin.y - oldOrigin.y) );
rootView.frame = frame;

...显然,每次都必须这样做很烦人。这就是为什么 Apple 强烈鼓励大家使用 UINavigationController 和/或 UITabBarController :)

【讨论】:

  • 我想我需要更仔细地阅读 Apple Docs :) 但无论如何,这确实有帮助。
  • 我还想知道是否应该通过将 rootController 的视图框架向上移动 20px 将其移回,以便 HHTabController 的其他子视图不会向下移动,但似乎其他视图不受影响全部,即使我多次调用 MailComposer(这会触发上面的重新定位代码)。你知道这是为什么吗?
  • 要弄清楚其他视图发生了什么,您需要仔细检查屏幕上每个视图的运行时 .frame 和 .bounds - 任何父视图都可能会自动更正其值孩子们。
【解决方案2】:

这种替代解决方案也非常方便处理顶部布局指南在以模态方式呈现视图控制器后重新定位自身的奇怪行为。

将顶部间距约束添加到“顶部布局指南”而不是实际“视图”。选择视图(当前距离...),如下图所示:

礼貌:https://stackoverflow.com/a/24818204/2959346

【讨论】:

    猜你喜欢
    • 2011-11-02
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多