ios - UIAlertController 被窗口上的 View 覆盖

标签 ios objective-c uialertcontroller

当我向 keyWindow 添加 UIView 时,alertController 被 View 覆盖。这是代码。

- (void)touch {
    UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
    UIView *viewhaha = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    viewhaha.backgroundColor = [UIColor redColor];
    [currentWindow addSubview:viewhaha];

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"123" message:@"123" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"123" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];

    [alertController addAction:action1];
    [self presentViewController:alertController animated:YES completion:^{
    }];
}    

这是图像。 Image

你知道如何解决吗?

最佳答案

窗口添加 View 将覆盖任何未添加到窗口并放置在其顶部的 View 。窗口层是您可以添加内容的最上层。如果您希望将 UIView 放置在 UIAlertViewController 下方,则必须将该 UIView 添加到 UIViewController 的 subview 中的 .view,您在其中呈现 UIAlertController

关于ios - UIAlertController 被窗口上的 View 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42406834/

相关文章:

ios - 如何在 ARKit 中使用手势 Action 在 SCNNode 中添加标签节点和用户图像?

ios - 从 iOS 应用程序将字典数据发送到 Apple Watch

ios - Swift iOS 16 我不能再从键盘上显示 UIViewController,而不关闭它

ios - 使用 UIAlertController 操作以编程方式链接到嵌入式 UIViewController

ios - UIAlertController 和内存使用

ios - 使用 cell 属性滚动到 UITableView 中的特定单元格

ios - 在 iOS7 中 "main" View 下的元素存储(弱或强)

ios - 如何使用 HyprMX

objective-c - NSURLConnection 在禁用互联网连接的情况下没有给出错误?

swift - UIAlertController : it does not close in a controlleView that a UICollectionView