从MSMessagesAppViewController正确呈现UIAlertController

klc*_*r89 13 objective-c ios msmessage

我正在试图弄清楚如何在我的iMessage应用扩展程序中显示UIAlertController一种风格UIAlertControllerStyleActionSheet.

问题是,当调用时,操作表显示在本机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];
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Sud*_*udo 3

这是一个解决方法。也许添加一点动画以使其流畅。

[self.view.window.rootViewController presentViewController:actionSheetController animated:YES completion:^{
    actionSheetController.view.frame = CGRectOffset(actionSheetController.view.frame, 0, -40);
}];
Run Code Online (Sandbox Code Playgroud)

  • 这是有问题的,因为任何布局过程都会将警报控制器的视图移动到其原始位置。 (2认同)