Custom UIWindow not showing

孤者浪人 提交于 2021-01-27 23:41:05

问题


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.

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.

For example:
This is the code from 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. It needs to be variable inside app delegate.

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


回答1:


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



来源:https://stackoverflow.com/questions/31892487/custom-uiwindow-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!