本文介绍了从MSMessagesAppViewController正确呈现UIAlertController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试弄清楚如何在我的iMessage应用中显示 UIAlertController ,样式为 UIAlertControllerStyleActionSheet 扩展。

I'm trying to figure out how to display a UIAlertController with a style of UIAlertControllerStyleActionSheet within my iMessage app extension.

问题是,在调用时出现的操作表显示在本机iMessage文本字段下方:

The problem is, the action sheet appears below the native iMessage text field when presented when calling:

[self.view.window.rootViewController presentViewController:actionSheetController animated:YES completion:NULL];

我要解决这个问题吗?

代码:

UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Clear", nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *clear = [UIAlertAction actionWithTitle:NSLocalizedString(@"Clear", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
{
    [self clear];
}];

UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action)
{}];

[actionSheetController addAction:clear];
[actionSheetController addAction:cancel];

[self.view.window.rootViewController presentViewController:actionSheetController animated:YES completion:NULL];

推荐答案

另一种解决方法:

actionSheetController.view.transform = CGAffineTransform(translationX: 0, y: -40)
[self.view.window.rootViewController presentViewController:actionSheetController animated:YES completion:NULL];

这篇关于从MSMessagesAppViewController正确呈现UIAlertController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 10:57