使用UIAppearance代理自定义字体时,MFMailComposeViewController无法工作。

3

如果我没有自定义我的应用程序中的字体,那么MFMailComposeViewController会被呈现并正常工作。但是当我这样做时,有50%的概率它会被呈现,并直接调用其委托以具有mailComposeController:didFinishWithResult:结果恰好与 MFMailComposeResultCancelled 相同,就像用户试图关闭它一样。

还会在控制台触发此错误:

_serviceViewControllerReady:error: Error Domain=XPCObjectsErrorDomain Code=2 "The operation couldn’t be completed. (XPCObjectsErrorDomain error 2.)"

看起来邮件编辑器不喜欢外观代理,但问题在于它甚至不可能为其禁用外观代理。

对于应用程序中的每个导航栏,我都有一个自定义设计。为了实现这一点,我使用了外观代理,如下所示:

UIImage *navBarBackground = [UIImage stretchableHorizontalImageNamed:@"navbar-background"];
[[UINavigationBar appearance] setBackgroundImage:navBarBackground forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"navbar-shadow"]];
[[UINavigationBar appearance] setTitleTextAttributes:@{
    UITextAttributeTextColor: [UIColor colorWithRed:0.965f green:0.635f blue:0.647f alpha:1.f],
    UITextAttributeFont : [UIFont brothersBoldFontOfSize:20.f],
    UITextAttributeTextShadowColor: [UIColor blackColor],
    UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)]
}];

UIBarButtonItem *navBarButtonItemAppearance = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil];
[navBarButtonItemAppearance setTitleTextAttributes:@{
    UITextAttributeTextColor: [UIColor colorWithRed:0.478f green:0.008f blue:0.023f alpha:1.f],
    UITextAttributeFont : [UIFont brothersBoldFontOfSize:17.f],
    UITextAttributeTextShadowColor: [UIColor colorWithWhite:1.f alpha:0.3f],
    UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 1)]
} forState:UIControlStateNormal];

我已删除弹出窗口的一些背景自定义,具体如下:
[[UINavigationBar appearanceWhenContainedIn:[UIPopoverController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

这个弹出框的功能非常好用。但是无法在邮件编辑器中删除它,即使我使用 "when contained in" MFMailComposeViewController 并将其设置为 nil,它仍然存在。

我还尝试过对其进行子类化或设置系统字体,但这并没有改变任何内容。它被呈现出来,打印错误,调用代理并被解除。我刚刚看到,当它正在工作时,系统不应用字体,而当它不工作时,它会以自定义字体呈现,如下所示:

enter image description here


嘿,你解决这个问题了吗?因为我也遇到了同样的问题,已经搜索了几天了。如果你成功解决了,请告诉我... :) - Krunal
1
我已经找到了解决方案...如果您在任何一个类中使用UINavigationBar设置了自定义字体,那么它将影响到MFMailComposeViewController。因此,您需要从所有类中删除自定义导航栏字体,这样它就可以正常工作了。我认为这是唯一的解决方案。您可能已经在Navigationbar中设置了自定义字体... :) - Krunal
1个回答

3

1
我也看到了这个链接,但是没有解决方案。绕过的代码在iOS 6上不起作用。 - Ludovic Landry

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