【发布时间】:2016-09-29 01:15:48
【问题描述】:
我正在尝试弄清楚如何在我的 iMessage 应用程序扩展中显示具有 UIAlertControllerStyleActionSheet 样式的 UIAlertController。
问题是,当调用时,操作表出现在原生 iMessage 文本字段下方:
[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];
【问题讨论】:
-
你能在
MSMessagesAppViewController上介绍UIAlertController吗? -
这是一个已知问题。来自 iOS 10/10.1 发行说明:“当 UIAlertController 对象出现在 Messages 扩展中时,它会被扩展的底栏截断。”打开错误报告告诉 Apple 这对您很重要。
-
iMessage 文本字段属于高于您的
self.view.window但低于状态栏的某个窗口。可能您可能想尝试使用windowLevel = UIWindowLevelStatusBar添加新的UIWindow并从该窗口显示警报 -
@VladFedoseev 刚刚尝试过,但没有成功。
UIWindow *window = UIWindow.new; window.rootViewController = self; window.windowLevel = UIWindowLevelStatusBar; [window makeKeyAndVisible]; [window.rootViewController presentViewController:alertController animated:YES completion:NULL]; -
我可以毫无问题地展示带有 AlertStyle 的 UIAlertController。但是,我在解雇时偶尔会崩溃,所以我建议创建一个 UIView 并将其作为子视图添加到 MSMessagesAppViewController
标签: ios objective-c msmessage