iOS 11 presentViewController会在呈现控制器后面进行。

5
我遇到了一个奇怪的问题,我只是简单地展示模态视图控制器。确切地说,是 MFMailComposeViewController。然而,它出现在呈现控制器的后面,因此您无法发送电子邮件或输入任何内容。您可以在邮件编辑器的 UINavigationBar 上看到“取消”按钮,但是这会弹出在呈现控制器后面的 UIAlertController。为什么会出现这种情况?这是一个 iOS 11 的问题吗?我也遇到了类似 UIAlertController 行为的问题。
此外,如果我按下发送并按下我的按钮以弹出另一个编辑器,它会像往常一样工作。只有第一个出现问题。
请查看我从 Xcode 得到的附加图像。

enter image description here

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在解除我最上面的控制器(一个菜单控制器)之前推送了新的控制器。这是一个简单的修复,但因为一开始并不明显,也没有错误日志,所以很难确定问题所在。


我也将这个放在了主线程上,以避免任何混淆。 - mashdup
不连VC的代码都没有吗? - LinusGeffarth
你在 iOS 10 上尝试过这段代码吗?你在一个干净的项目上尝试过这段代码吗? - Fyodor Volchyok
3
这不是解决方案,而是一个调试问题的提示:您可以设置mailer.transitioningDelegate并观察谁真正呈现了mailer,因为[self presentViewController:...]不能保证self将呈现另一个视图控制器。 - Mert Buran
你的contentView是什么?它的frame尺寸是多少? - manismku
显示剩余8条评论
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接