从 AppDelegate 呈现 UIAlertController 后无法单击任何内容
Can't click on anything after presenting UIAlertController from AppDelegate
我在 AppDelegate 中展示了一个来自额外 window 根视图控制器的 UIAlerController
。
//AppDelegate.h
@property (strong, nonatomic) UIWindow *alertWindow;
//SomeViewController.m
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* action = [UIAlertAction actionWithTitle:@"action" style:UIAlertActionStyleDefault
handler:^(UIAlertAction* a){[alert dismissViewControllerAnimated:true completion:nil];});
[alert addAction:action];
appDelegate.alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
appDelegate.alertWindow.rootViewController = [[UIViewController alloc] init];
appDelegate.alertWindow.windowLevel = UIWindowLevelAlert + 1;
[appDelegate.alertWindow makeKeyAndVisible];
[appDelegate.alertWindow.rootViewController presentViewController:alert animated:true completion:nil];
当此 UIAlertController
关闭时,我无法再与屏幕上的任何内容进行交互。有什么想法吗?谢谢
删除行:
appDelegate.alertWindow.windowLevel = UIWindowLevelAlert + 1;
您的 UIAlertController 在 alertWindow 下并且没有接收到触摸。
所以我通过将其添加到按钮的处理程序中来修复此问题:
[appDelegate.window makeKeyAndVisible];
appDelegate.window.windowLevel = UIWindowLevelAlert + 1;
不确定这是否是正确的修复方法,但它现在可以完成工作...如果有人能对此有所说明,我们将不胜感激。
不要试图关闭警报控制器。当警报操作的处理程序被调用时,它将被解除。
仅在处理程序中隐藏或销毁 alertWindow。
在这里试试这个:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Action" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
appDelegate.alertWindow.hidden = YES;
appDelegate.alertWindow = nil;
}];
[alert addAction:alertAction];
appDelegate.alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
appDelegate.alertWindow.rootViewController = [[UIViewController alloc] init];
appDelegate.alertWindow.windowLevel = UIWindowLevelAlert + 1;
[appDelegate.alertWindow makeKeyAndVisible];
[appDelegate.alertWindow.rootViewController presentViewController:alert animated:true completion:nil];
我在 AppDelegate 中展示了一个来自额外 window 根视图控制器的 UIAlerController
。
//AppDelegate.h
@property (strong, nonatomic) UIWindow *alertWindow;
//SomeViewController.m
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* action = [UIAlertAction actionWithTitle:@"action" style:UIAlertActionStyleDefault
handler:^(UIAlertAction* a){[alert dismissViewControllerAnimated:true completion:nil];});
[alert addAction:action];
appDelegate.alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
appDelegate.alertWindow.rootViewController = [[UIViewController alloc] init];
appDelegate.alertWindow.windowLevel = UIWindowLevelAlert + 1;
[appDelegate.alertWindow makeKeyAndVisible];
[appDelegate.alertWindow.rootViewController presentViewController:alert animated:true completion:nil];
当此 UIAlertController
关闭时,我无法再与屏幕上的任何内容进行交互。有什么想法吗?谢谢
删除行:
appDelegate.alertWindow.windowLevel = UIWindowLevelAlert + 1;
您的 UIAlertController 在 alertWindow 下并且没有接收到触摸。
所以我通过将其添加到按钮的处理程序中来修复此问题:
[appDelegate.window makeKeyAndVisible];
appDelegate.window.windowLevel = UIWindowLevelAlert + 1;
不确定这是否是正确的修复方法,但它现在可以完成工作...如果有人能对此有所说明,我们将不胜感激。
不要试图关闭警报控制器。当警报操作的处理程序被调用时,它将被解除。
仅在处理程序中隐藏或销毁 alertWindow。
在这里试试这个:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Action" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
appDelegate.alertWindow.hidden = YES;
appDelegate.alertWindow = nil;
}];
[alert addAction:alertAction];
appDelegate.alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
appDelegate.alertWindow.rootViewController = [[UIViewController alloc] init];
appDelegate.alertWindow.windowLevel = UIWindowLevelAlert + 1;
[appDelegate.alertWindow makeKeyAndVisible];
[appDelegate.alertWindow.rootViewController presentViewController:alert animated:true completion:nil];