【问题标题】:iOS 11 presentViewController going behind presenting controlleriOS 11 presentViewController 落后于呈现控制器
【发布时间】:2017-10-06 16:23:12
【问题描述】:

我遇到了一个奇怪的问题,我只是在做一个简单的呈现模式视图控制器。 MFMailComposeViewController 确切地说。但是,它出现在演示控制器的后面,因此您无法发送任何电子邮件或类型。您可以在邮件编写器的UINavigationBar 上看到“取消”按钮,但这会在呈现控制器后面弹出UIAlertController。这是怎么发生的?是 iOS 11 的问题吗?我也对UIAlertControllers 有类似的行为。

另外,如果我按下发送并按下按钮弹出另一个 Composer,它会正常工作。这只是第一个。

请查看我从 Xcode 获得的附加图片。

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
mailer.modalPresentationStyle = UIModalPresentationFormSheet;
[mailer setSubject:@"subject Feedback"];
[mailer setToRecipients:@[@"email address"]];
[mailer setMessageBody:@"" isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];

编辑:添加控制器以获取更多信息。

#import "AboutViewController.h"
#import <MessageUI/MessageUI.h>


@interface AboutViewController () <MFMailComposeViewControllerDelegate>
@property (nonatomic, strong) IBOutlet UIView *contentView;
@end

@implementation AboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"About this app";
    _contentView.layer.cornerRadius = 10.;
    _contentView.layer.shadowColor = [UIColor blackColor].CGColor;
    _contentView.layer.shadowRadius = 3.;
    _contentView.layer.shadowOpacity = 0.4;
    _contentView.layer.shadowOffset = CGSizeMake(3., 3.);
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)sendFeedbackEmail:(id)sender {
    if ([MFMailComposeViewController canSendMail]){
        dispatch_async(dispatch_get_main_queue(), ^{
            MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
            mailer.mailComposeDelegate = self;
            mailer.modalPresentationStyle = UIModalPresentationFormSheet;
            [mailer setSubject:@"Feedback"];
            [mailer setToRecipients:@[@"email@email.com"]];
            [mailer setMessageBody:@"" isHTML:NO];
            [self presentViewController:mailer animated:YES completion:nil];

        });
    } else {
        NSLog(@"Nope");
    }
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    [controller dismissViewControllerAnimated:YES completion:nil];
}

编辑 2:

我相信我已经找到了答案。我希望这可以帮助遇到同样问题的任何人。谢谢大家的回复,帮助我找到了答案。感谢@Mert Buran 的代表想法。这表明它第一次有一个不同的过渡委托,而第二次我想要一个。

问题在于,navigationController 在关闭我在顶部的控制器(菜单控制器)之前推送了新控制器。一个简单的修复,但由于一开始并不明显且没有错误日志,因此很难确定。

【问题讨论】:

标签: ios ios11 modalviewcontroller mfmailcomposeviewcontroller


【解决方案1】:

我会在您的viewDidLoad 中尝试self.definesPresentationContext = YES。见https://developer.apple.com/documentation/uikit/uiviewcontroller/1621456-definespresentationcontext

【讨论】:

    猜你喜欢
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多