问题
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