简体   繁体   English

防止在出现警报时显示视图控制器

[英]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.

相关问题 如何防止在出现警报时显示视图控制器的 inputAccessoryView? - How to prevent inputAccessoryView of a view controller from being shown when an alert is presented? 视图控制器显示不正确 - View Controllers not being presented correctly 无法通过显示的视图控制器访问TopView - TopView is not accessible from presented view controllers 在根视图上显示另一个视图时,警报视图中心会更改 - Alert view center changes when another view is presented on root view 当从UIBarButtonItem呈现方向更改后,如何防止UIPopoverController passthroughViews被重置? - How do I prevent UIPopoverController passthroughViews from being reset after orientation change when presented from a UIBarButtonItem? 所有呈现的视图控制器都不会被解雇 - All the presented view controllers are not dismissed Swift:展示了两个视图控制器 - Swift: Two View Controllers presented 如何从多个导航控制器中选择一个视图控制器,完成后如何快速返回显示的任何一个视图控制器 - How to segue to one view controller from multiple navigation controllers and when done go back to whichever view controller presented it swift 当本地显示视图控制器并显示警报时,控件不会变暗 - Controls not dimming when view controller is presented locally and alert displayed 是否需要从顶视图控制器显示警报视图? - Do alert views need to be presented from the top view controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM