为什么我看不到我的新 UIWindow?

编程入门 行业动态 更新时间:2024-10-25 14:31:12
本文介绍了为什么我看不到我的新 UIWindow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

场景:创建并显示一个覆盖(辅助)UIWindow.相关讨论:

重要说明:如果我在 displayOverLay() 结束时刹车并执行po myWindow",然后继续,我确实得到了显示.

因此,似乎我缺少某种事件来显示 UIWindow.需要什么来强制实际显示带有内容的新 UIWindow?

解决方案

您需要保留对创建的窗口的引用,否则 ARC 会在您从函数返回后处理该窗口.

例如,您可以从您的函数返回新创建的窗口,并将其存储在您调用该函数的类的属性中.

Scenario: Create and display an overlay (ancillary) UIWindow. Related Discussion: How do I toggle between UIWindows?

Code:

fileprivate func displayOverLay() { let myWindow = {() -> UIWindow in let cWindow = UIWindow(frame: CGRect(x: 10, y: 200, width: 300, height: 300)) cWindow.backgroundColor = UIColor.gray.withAlphaComponent(0.5) cWindow.tag = 100 return cWindow }() myWindow.makeKeyAndVisible() myWindow.windowLevel = UIWindowLevelAlert let storyboard = UIStoryboard(name: "Hamburger", bundle: nil) let vc = storyboard.instantiateInitialViewController() myWindow.rootViewController = vc return }

Here's the shared UIApplication window status:

(lldb) po UIApplication.shared.windows ▿ 2 elements - 0 : <UIWindow: 0x7fcffc804860; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000051280>; layer = <UIWindowLayer: 0x60000003e840>> - 1 : <UIWindow: 0x7fcff9407240; frame = (10 200; 300 300); tag = 100; gestureRecognizers = <NSArray: 0x608000052810>; layer = <UIWindowLayer: 0x608000220420>> (lldb) po UIApplication.shared.keyWindow! <UIWindow: 0x7fcff9407240; frame = (10 200; 300 300); tag = 100; gestureRecognizers = <NSArray: 0x608000052810>; layer = <UIWindowLayer: 0x608000220420>>

Here's the result: no gray window sceen

Important Note: If I brake at the end of the displayOverLay() and do a 'po myWindow', and then continue, I do get the display.

So it appears that I'm missing some sort of event to have the UIWindow appear. What is needed to force the new UIWindow w/contents to actually display?

解决方案

You need to keep a reference to the created window, otherwise ARC will take care of disposing the window after you return from your function.

You could for instance return the newly created window from your function and store it in a property of the class from which your are calling the function.

更多推荐

为什么我看不到我的新 UIWindow?

本文发布于:2023-10-16 05:23:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496625.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UIWindow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!