22

下面的代码在 iOS 5/6 中运行良好。在 iOS 7 中,它看起来像这样(红色椭圆表示强调)。

在此处输入图像描述

代码:

if ([MFMessageComposeViewController canSendText]) {
    self.messageComposer = [MFMessageComposeViewController new];
    self.messageComposer.recipients = @[number];
    self.messageComposer.messageComposeDelegate = self;
    [self presentViewController:self.messageComposer
                       animated:YES
                     completion:nil];
}

问题:这是简单的代码。是否有其他一些外部属性(可能是呈现视图控制器的)会影响这一点?有人有修复或解决方法吗?

谢谢。

4

2 回答 2

20

我发现 MFMessageComposeViewController 的收件人字段似乎从 iOS7 中的 UINavigationBar 外观代理中获取了一些外观。为了解决这个问题,我在我的应用程序中执行了以下操作:

  1. 创建一个空的自定义 UINavigationController 子类,它不会覆盖任何 UINavigationController 的方法。

  2. 通过在 IB 中的身份检查器上设置自定义类,将此自定义 UINavigationController 子类用作我想要具有自定义外观的任何导航控制器的标记:

    在此处输入图像描述

  3. 在我的应用程序委托中,设置导航栏的外观,如下所示:

     [[UINavigationBar appearanceWhenContainedIn:[MyCustomNavigationController class], nil] ...];
    

这可确保我在要自定义的控制器中获得所需的导航栏外观,但在其他控制器(如 MFMessageComposeViewController)中保留标准导航栏(和相关)外观。这是截图;注意 MFMessageComposeViewController 的标准外观,以及背景弹出框上的自定义导航栏外观:

在此处输入图像描述

于 2013-09-30T23:54:16.303 回答
20

我遇到了同样的问题,这是我的解决方案-

在呈现您的消息 composer( [self presentViewController:messageComposer animated:YES completion:nil];) 集之前

[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

并在委托方法中

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
                 didFinishWithResult:(MessageComposeResult)result {
     UIImage *backgroundImage = [UIImage imageNamed:@"Navigation Bar"];
    [[UINavigationBar appearance] setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
    [self dismissViewControllerAnimated:YES completion:nil];
}

就这样!!

于 2013-12-13T10:42:29.287 回答