检查UIView是否显示UIAlertView

Smi*_*key 4 objective-c subview uiview uialertview ios

是否可以确定当前UIView是否显示UIAlertView(除了每次创建UIAlertView时设置变量).

我正在思考一些事情

    if ([self.view.subviews containsObject:UIAlertView]) { ... }
Run Code Online (Sandbox Code Playgroud)

但这显然不起作用.

War*_*shi 16

这在iOS7及更高版本中无效.

[alertView Show]我想在主窗口上添加子视图.

for (UIWindow* window in [UIApplication sharedApplication].windows){
    for (UIView *subView in [window subviews]){
        if ([subView isKindOfClass:[UIAlertView class]]) {
            NSLog(@"has AlertView");
        }else {
            NSLog(@"No AlertView");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


Kyl*_*e C 10

我认为它会起作用:

-(BOOL) doesAlertViewExist 
{
    if ([[UIApplication sharedApplication].keyWindow isMemberOfClass:[UIWindow class]])
    {
        return NO;//AlertView does not exist on current window
    }
    return YES;//AlertView exist on current window
}
Run Code Online (Sandbox Code Playgroud)