自定义 UIWindow 未显示 [英] Custom UIWindow not showing

查看:41
本文介绍了自定义 UIWindow 未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义窗口

I create a custom window

let alertWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
let background = UIToolbar(frame: alertWindow.frame)
background.barStyle = .Black
background.translucent = true
alertWindow.addSubview(background)
alertWindow.makeKeyAndVisible()

仅当我将 UIWindow 变量作为全局变量放入 AppDelegate 时才会出现.

It only appears if I put the UIWindow variable as the global variable inside the AppDelegate.

我看到许多 Pod 使用自定义 UIWindow 作为通知横幅或自定义 AlertView.但是他们并没有将他们的自定义 UIWindow 放在 AppDelegate 中,而是在他们的自定义类中.

I see many Pods out there that using custom UIWindow for notification banner or custom AlertView. But they didn't put their custom UIWindow inside the AppDelegate, it's inside their custom class.

例如:
这是来自 CRToast 的代码https://github.com/cruffenach/CRToast

@interface CRToastManager () <UICollisionBehaviorDelegate>
@property (nonatomic, readonly) BOOL showingNotification;
@property (nonatomic, strong) UIWindow *notificationWindow;
@property (nonatomic, strong) UIView *statusBarView;
@property (nonatomic, strong) UIView *notificationView;

他将他的自定义窗口放在 CRToastManager 类中,而不是应用程序委托中,在我的情况下,当我将它放在自定义类中时,它没有出现.它需要在应用程序委托中可变.

He put his custom window inside the CRToastManager class, not the app delegate, in my case when I put it inside my custom class, it doesn't appear. It needs to be variable inside app delegate.

如何显示自定义窗口并将其放入自定义类?

How to show custom window and put it in custom class?

推荐答案

您是否尝试使用窗口内容创建 ViewController 并设置 rootViewController 属性?

Did you try to create a ViewController with your window content and set the rootViewController property?

这篇关于自定义 UIWindow 未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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