2

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?

Edward Anthony
  • 3,354
  • 3
  • 25
  • 40

1 Answers1

0

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

Lucian Boboc
  • 480
  • 2
  • 6
  • I tried, it didn't appear unless the window is a global variable inside the AppDelegate class. – Edward Anthony Aug 08 '15 at 11:18
  • @EdwardAnthony what about windowLevel? Was it set to UIWindowLevelAlert ? – Lucian Boboc Aug 08 '15 at 11:23
  • Yes, I set it to UIWindowLevelAlert, still didn't work. I read this http://stackoverflow.com/questions/28002992/custom-uiwindow-not-display it needs to be global var in order to work. But CRToast put the window variable in his custom class. – Edward Anthony Aug 08 '15 at 11:32
  • You need to save a reference to your second window somewhere, you can have it in AppDelegate like the main window. I have a property in AppDelegate, i have set only the windowLevel and its showing. – Lucian Boboc Aug 08 '15 at 11:41
  • Yes it's right, the reference must be in AppDelegate and I already tried that and it worked, But a lot of Pods out there using custom UIWindow outside AppDelegate, If I put the custom window in the AppDelegate it won't be a Pod. – Edward Anthony Aug 08 '15 at 12:09
  • 1
    @EdwardAnthony it doesn't have to be there, it has to be somewhere keeped with a strong reference to be able to present it. – Lucian Boboc Aug 08 '15 at 12:12