iOS 7状态栏中的MFMailComposeViewController为黑色

iOS 7状态栏中的MFMailComposeViewController为黑色,ios,ios7,mfmailcomposeviewcontroller,Ios,Ios7,Mfmailcomposeviewcontroller,我的ios 7应用程序中有一个带有MFMailComposeViewController的反馈按钮。用户单击此按钮后,mailcomposer将打开,但状态栏变为黑色。有人知道我能做什么吗 我只有ios7有这个问题。我正在为ios7定制我的应用程序 MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; mailController.mail

我的ios 7应用程序中有一个带有MFMailComposeViewController的反馈按钮。用户单击此按钮后,mailcomposer将打开,但状态栏变为黑色。有人知道我能做什么吗

我只有ios7有这个问题。我正在为ios7定制我的应用程序

    MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
            mailController.mailComposeDelegate = self;

            [mailController setSubject:@"Feedback"];
            // Fill out the email body tex
            NSString *emailBody = [NSString stringWithFormat:@"testest"],
                                   [UIDevice currentDevice].model,
                                   [UIDevice currentDevice].systemVersion];
            [mailController setMessageBody:emailBody isHTML:NO];
            [mailController setToRecipients:[NSArray arrayWithObjects:@"support@test.com",nil]];

            dispatch_async(dispatch_get_main_queue(), ^{
                [self presentModalViewController:mailController animated:YES];
}

iOS 7引入了一种方法
prefersStatusBarHidden
,但在这种情况下使用起来并不容易。当显示模式时,您可能更喜欢使用
ui应用程序的
statusBarHidden
属性。

尝试将类别添加到MFMailComposeViewController

编辑:如果“查看基于控制器的状态栏外观”==是,则此解决方案有效


为MFMailComposeViewController在presentViewController的完成块中设置UIApplication statusBarStyle。i、 e

    MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
    [self.navigationController presentViewController:mailVC animated:YES completion:^{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }];

您可能还需要在Info.plist文件中添加和/或将“基于视图控制器的状态栏外观”设置为否

我的诀窍是:

extension MFMailComposeViewController {

    open override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        UIApplication.shared.statusBarStyle = .lightContent
    }
}
  • 子类MFMailComposeViewController
  • 覆盖答案6中所述的两种方法

    -(UIStatusBarStyle)首选状态BarStyle

    -(UIViewController*)childViewControllerForStatusBarStyle

  • 覆盖viewDidLoad,如下所示:

    -(void)viewDidLoad{
    [超级视图下载];
    [self-preferredStatusBarStyle];
    [self-setNeedsStatusBarAppearanceUpdate];
    }


有时它无法正确更新状态栏样式。你应该使用

 [self setNeedsStatusBarAppearanceUpdate];
要说iOS刷新状态栏样式,请手动。希望有人能节省一些时间来了解它

[self presentViewController:picker animated:YES completion:^{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
     [self setNeedsStatusBarAppearanceUpdate];
}];
在我的例子中,我使用了“基于视图控制器的状态栏外观”,展示了一个带有自定义segue转换的模态视图控制器,然后从那里展示了MFMailComposeViewController。在这种情况下,默认情况下,iOS只尊重/使用呈现或“根”视图控制器的
preferredStatusBarStyle
方法

因此,一旦我在我的根视图控制器和模态视图控制器中分别覆盖了
childViewControllerForStatusBarStyle
preferredStatusBarStyle
,一切都按预期进行了。。。大概是这样的:

// in RootViewController.m ...
- (UIViewController *)childViewControllerForStatusBarStyle {
    return self.modalViewController;
}

// in ModalViewController.m ...
- (UIStatusBarStyle)preferredStatusBarStyle {
    if (self.mailController != nil)
        return UIStatusBarStyleDefault;
    return UIStatusBarStyleLightContent;
}

以上答案都不适合我

我有两个问题

  • 黑色状态栏
  • 标题栏上的透明层
  • 解决方案

  • 黑色状态-我删除所有导航栏自定义

    //AppDelegate中行下方的注释

    [[UINavigationBar外观]setBackgroundImage:[UIImage ImageName:@“nav_bg”]forBarMetrics:UIBarMetricsDefault]

  • 透明标题栏-为MFMailComposeViewController设置navigationBarHidden=Yes

    composeViewController.navigationBarHidden=是


  • 我正在iOS8中构建一个应用程序,并且所有本机功能(如邮件生成器、照相机等)的状态栏都出现问题。。以下内容将解决您的问题:

    将以下内容放入plist文件中

      <key>UIStatusBarHidden</key>
      <false/>
      <key>UIViewControllerBasedStatusBarAppearance</key>
      <false/>
    
    迅速解决。 将
    查看基于控制器的状态栏外观
    设置为

    import UIKit
    import MessageUI
    import AddressBookUI
    
    extension MFMailComposeViewController {
        override func preferredStatusBarStyle() -> UIStatusBarStyle {
            return .LightContent
        }
    
        override func childViewControllerForStatusBarStyle() -> UIViewController? {
            return nil
        }
    }
    
    extension ABPeoplePickerNavigationController {
        override func preferredStatusBarStyle() -> UIStatusBarStyle {
            return .LightContent
        }
    
        override func childViewControllerForStatusBarStyle() -> UIViewController? {
            return nil
        }
    }
    

    似乎初始化MFMailComposeViewController UIApplication.shared.statusBarStyle将更改为.default。。。因此,在演示之前保存状态并在演示之后再次设置状态为我解决了问题:

        // save the state, otherwise it will be changed
        let sbs = UIApplication.shared.statusBarStyle
    
        let mailComposerVC = MailComposerVC()
        mailComposerVC.navigationBar.barTintColor = UINavigationBar.appearance().barTintColor
        mailComposerVC.navigationBar.tintColor = UINavigationBar.appearance().tintColor
        mailComposerVC.navigationBar.barStyle = UINavigationBar.appearance().barStyle
    
        if MFMailComposeViewController.canSendMail() {
            APP_ROOT_VC?.present(mailComposerVC, animated: true, completion: {
                // reapply the saved state
                UIApplication.shared.statusBarStyle = sbs
            })
        }
    
        public class MailComposerVC: MFMailComposeViewController {
    
            public override var preferredStatusBarStyle: UIStatusBarStyle {
                return UIApplication.shared.statusBarStyle
            }
            public override var childViewControllerForStatusBarStyle : UIViewController? {
                return nil
            }
        }
    

    Swift3的解决方案

    将其添加到ViewController:

    extension MFMailComposeViewController {
        open override var preferredStatusBarStyle: UIStatusBarStyle {
            return .lightContent
        }
        open override var childViewControllerForStatusBarStyle: UIViewController? {
            return nil
        }
    }
    
    将基于控制器的状态栏外观设置为“是”,如下所示:

    感谢@SoftDesigner

    另一个更清洁的解决方案可能不会更改应用程序中的其他设置。显示邮件时,更改完成块中的状态栏:

    controller.present(mailComposeViewController, animated: true) {
                UIApplication.shared.statusBarStyle = .lightContent
            }
    

    对我来说,最简单的swift 3解决方案是:

    extension MFMailComposeViewController {
    
        open override func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
    
            UIApplication.shared.statusBarStyle = .lightContent
        }
    }
    

    谢谢你的回答。我使用:[[UIApplication sharedApplication]setStatusBarHidden:NO with animation:UIStatusBaranimationne]测试它;同样的问题:(这不起作用,因为视图控制器及其状态栏完全由不同的进程呈现(MailCompositionService)。这只会影响外部进程加载时设置动画的预览视图控制器。如果重写MFMailComposeViewController类并仅实现这两个方法,它会工作!这会工作!我添加了完全相同的类别,
    childViewControllerForStatusBarStyle
    的工作做得很好!没有它,但没有它这种情况经常发生。这对我也有帮助。如果你想使设置成为全局设置,Keller的答案会起作用,但如果你不这样做,这个答案会起作用。你不应该覆盖某个类别中的现有方法。这会导致意外行为。你可以在这里了解更多:如果你在Info.plist中做了更改,我认为在哪里做并不重要setStatusBarStyle,因为它成为应用程序的全局设置。这不应标记为正确答案,因为此时preferredStatusBarStyle处于启用状态useless@mackinra:不完全正确。我在plist和app委托上设置了它,但在我的情况下,MailViewComposeViewController将其覆盖为黑白。此解决方案已将其修复,如下所示:eird就是这样。我不得不做
    [self-presentViewController:mailVC…
    而不是
    [self.navigationController…
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];现在被弃用了,所以我不知道该做什么。根据我的经验,覆盖这两种方法已经足够了。这行是怎么回事[self-preferredStatusBarStyle];do?它只获取样式,然后不进行任何处理。这似乎是iOS 9的正确答案。(好吧,在删除“public”关键字之后。)如果您想要更广泛的解决方案,可以扩展UINavigationController并覆盖preferredStatusBarStyle和childViewControllerForStatusBarStyle。这适用于MFMailComposeViewController和共享工作表pre
    controller.present(mailComposeViewController, animated: true) {
                UIApplication.shared.statusBarStyle = .lightContent
            }
    
    extension MFMailComposeViewController {
    
        open override func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
    
            UIApplication.shared.statusBarStyle = .lightContent
        }
    }