参见英文答案 >
iPhone SDK: check if a UIAlertView is showing10个
> Check if UIView is displaying a UIAlertView3个
我可以在iOS应用程序的任何部分检查是否有任何UIAlertView现在显示?我找到了这段代码
> Check if UIView is displaying a UIAlertView3个
我可以在iOS应用程序的任何部分检查是否有任何UIAlertView现在显示?我找到了这段代码
[NSClassFromString(@"_UIAlertManager") performSelector:@selector(topMostAlert)]
但它是私有API,我的应用程序可能会被Apple拒绝.
有没有合法的方法来做到这一点?
解决方法
对于低于iOS 7的设备: –
当您创建UIAlertView的主体时,[alertView Show]会在主窗口中添加子视图.因此,要检测UIAlertView,您只需检查当前UIView的子视图,因为UIAlertView继承自UIView.
for (UIWindow* window in [UIApplication sharedApplication].windows){ for (UIView *subView in [window subviews]){ if ([subView isKindOfClass:[UIAlertView class]]) { NSLog(@"AlertView is Present"); }else { NSLog(@"AlertView Not Available"); } } }
编辑: – 适用于使用iOS 7的设备
Class UIAlertManager = objc_getClass("_UIAlertManager"); UIAlertView *Alert = [UIAlertManager performSelector:@selector(Alert)];
和
UIAlertView *Alert = [NSClassFromString(@"_UIAlertManager") performSelector:@selector(Alert)];
注意: – 如果您不能使用第三方API,那么iOS7中唯一真正的选项是实际跟踪您的警报视图.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。