[英]Prevent view controllers from being presented when alert is there
I have some code that asynchronously checks for errors and if an error happens, it shows an alert using window.rootViewController?.present(...)
我有一些代码异步检查错误,如果发生错误,它会使用
window.rootViewController?.present(...)
显示警报window.rootViewController?.present(...)
Sometimes, this happens right before a view controller is presented, so the alert is shown for a split second and then the new view controller goes on top of it. 有时,这是在显示视图控制器之前发生的,因此会在一秒钟内显示警报,然后新的视图控制器会放在其顶部。
The thing is that the new VC is also presented asynchronously (ie, when an HTTP request finishes). 事实是,新的VC也可以异步呈现(即,HTTP请求完成时)。
Is there a way to make alerts really modal? 有没有办法使警报真正具有模态性? How to approach this?
如何处理呢?
Perhaps this can help: What is the best way to check if a UIAlertController is already presenting? 也许这会有所帮助: 检查UIAlertController是否已经显示的最佳方法是什么?
I would try checking if the presentedViewController
property is different from nil, even if it was presented a split second before, the property should contain the view controller that was presented. 我会尝试检查
presentedViewController
属性是否与nil不同,即使之前曾短暂呈现过该属性,该属性也应包含所呈现的视图控制器。 If that is the case, you avoid presenting a new one. 如果是这种情况,您可以避免提出新的建议。
Another option is to add a view to an additional window above everything so that there is no way anything can be presented over it. 另一种选择是将视图添加到所有内容上方的其他窗口中,以便无法在其上呈现任何内容。 You could present it at UIWindowLevelAlert or other level and it would be over all controllers.
您可以在UIWindowLevelAlert或其他级别上显示它,并且它将显示在所有控制器上。 An example that I am pretty sure that is in its own window is the volume view in Instagram that slides down to cover the view.
我敢肯定,在它自己的窗口中的一个示例是Instagram中的体积视图,该视图向下滑动以覆盖该视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.