Programing

iOS 7 상태 표시 줄의 MFMailComposeViewController가 검은 색입니다.

lottogame 2020. 12. 6. 20:52
반응형

iOS 7 상태 표시 줄의 MFMailComposeViewController가 검은 색입니다.


MFMailComposeViewController가있는 iOS 7 응용 프로그램에 피드백 버튼이 있습니다. 사용자가이 버튼을 클릭하면 메일 작성기가 열리지 만 상태 표시 줄이 검은 색으로 변경됩니다. 내가 무엇을 할 수 있는지 아는 사람이 있습니까?

나는 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];
}

MFMailComposeViewController에 대한 presentViewController의 완료 블록에서 UIApplication statusBarStyle을 설정합니다.

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

Info.plist 파일에서 "View controller-based status bar appearance"를 NO로 추가 및 / 또는 설정해야 할 수도 있습니다.


MFMailComposeViewController에 범주를 추가하십시오.

편집 : "컨트롤러 기반 상태 표시 줄 모양보기"== 예인 경우이 솔루션이 작동합니다.

@implementation MFMailComposeViewController (IOS7_StatusBarStyle)

-(UIStatusBarStyle)preferredStatusBarStyle
{
   return UIStatusBarStyleLightContent;
}

-(UIViewController *)childViewControllerForStatusBarStyle
{
   return nil;
}

@end

신속한 솔루션. 설정 View controller-based status bar appearanceYES

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
  • 답변 6에 설명 된대로 두 가지 방법을 재정의하십시오.

    -(UIStatusBarStyle)preferredStatusBarStyle;

    -(UIViewController *)childViewControllerForStatusBarStyle;

  • 다음과 같이 viewDidLoad를 재정의합니다.

    -(void)viewDidLoad {
    [super viewDidLoad];
    [self preferredStatusBarStyle];
    [self setNeedsStatusBarAppearanceUpdate];
    }


Swift3 솔루션

이것을 ViewController에 추가하십시오.

extension MFMailComposeViewController {
    open override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
    open override var childViewControllerForStatusBarStyle: UIViewController? {
        return nil
    }
}

View controller-based status bar appearance>> YES를 아래와 같이 설정하십시오 .

여기에 이미지 설명 입력

@SoftDesigner 덕분에

앱의 다른 설정을 변경할 수없는 또 다른 클리너 솔루션입니다. Mail VC를 표시하는 동안 완료 블록의 상태 표시 줄을 변경합니다.

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

때때로 상태 표시 줄 스타일이 제대로 업데이트되지 않습니다. 당신은 사용해야합니다

 [self setNeedsStatusBarAppearanceUpdate];

상태 표시 줄 스타일을 새로 고치도록 iOS라고 말하려면 수동으로. 누군가가 그것을 아는 데 시간을 절약하기를 바랍니다.

[self presentViewController:picker animated:YES completion:^{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
     [self setNeedsStatusBarAppearanceUpdate];
}];

나에게 가장 쉬운 신속한 3 솔루션은 다음과 같습니다.

extension MFMailComposeViewController {

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

        UIApplication.shared.statusBarStyle = .lightContent
    }
}

위의 답변 중 어느 것도 나를 위해 일하지 않습니다.

두 가지 문제가 있습니다.

  1. 검은 색 상태 표시 줄
  2. 제목 표시 줄의 투명 레이어

여기에 이미지 설명 입력

해결책

  1. 검은 색 상태 -모든 탐색 모음 사용자 지정을 제거합니다.

    // comment below line in AppDelegate

    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg"] forBarMetrics:UIBarMetricsDefault];

  2. Transparent title bar - set navigationBarHidden = Yes for MFMailComposeViewController

    composeViewController.navigationBarHidden = YES;


It seems that initializing the MFMailComposeViewController UIApplication.shared.statusBarStyle will change to .default... so, saving the state before and setting it again after presentation solved the problem for me:

    // 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
        }
    }

iOS 7 introduces a method prefersStatusBarHidden, but it won't be so easy to use in this case. You may prefer to use the statusBarHidden property of UIApplication while the modal is presented.


[self presentViewController:mailViewController animated:YES completion:^(void) { [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES]; }];

In my case, I was using "view controller-based status bar appearance" and presenting a modal view controller with a custom segue transition and then presenting the MFMailComposeViewController from there. In this situation, by default, iOS only respects/uses the presenting or "root" view controller's preferredStatusBarStyle method.

So once I overrode childViewControllerForStatusBarStyle in my root view controller and preferredStatusBarStyle in my modal view controller, everything worked as expected... something like this:

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

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

I am building an application in iOS8 and have had issues with the status bar with all native functions such as the mail composer, the camera, etc.. The following will solve your issues:

Put the following in your plist file

  <key>UIStatusBarHidden</key>
  <false/>
  <key>UIViewControllerBasedStatusBarAppearance</key>
  <false/>

If you are using the add row feature in storyboard, the UIViewControllerBasedStatusBarAppearance is not an option. Also when adding a row it asks for BOOLEAN (YES/NO). It cannot be a NO string in the source code it must be a false boolean. Open the plist as source code instead and add the above rows. Remove your old attempts. You will now be able to successfully apply the code snippets given in so many incomplete answers found on the net.

You can now add global changes in the app delegate file and/or overrides in the controllers themselves. Without the above being in place all the stack overflow code I have tried has failed when using a native function. Now all is working perfectly.

As a test, replace any calls to any onboard "completion" calls with

    completion:^{[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];}

참고 URL : https://stackoverflow.com/questions/18945390/mfmailcomposeviewcontroller-in-ios-7-statusbar-are-black

반응형