为什么我看不到我的新 UIWindow? [英] Why do I not see my new UIWindow?

查看:38
本文介绍了为什么我看不到我的新 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆