简体   繁体   English

自定义UIWindow不显示

[英]Custom UIWindow not showing

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()

It only appears if I put the UIWindow variable as the global variable inside the AppDelegate. 仅当我将UIWindow变量作为AppDelegate内的全局变量时,它才会出现。

I see many Pods out there that using custom UIWindow for notification banner or custom AlertView. 我在那里看到很多Pod,它们使用自定义UIWindow作为通知横幅或自定义AlertView。 But they didn't put their custom UIWindow inside the AppDelegate, it's inside their custom class. 但是他们没有将自定义UIWindow放在AppDelegate中,而是在自定义类中。

For example: 例如:
This is the code from CRToast https://github.com/cruffenach/CRToast 这是来自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;

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. 他将自定义窗口放在CRToastManager类而不是应用程序委托中,在我而言,当我将其放在自定义类中时,它不会出现。 It needs to be variable inside app delegate. 它必须在应用程序委托中是可变的。

How to show custom window and put it in custom class? 如何显示自定义窗口并将其放在自定义类中?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM