2015-08-08 93 views
0

創建自定義窗口自定義一個UIWindow沒有顯示

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的內部全局變量出現。

我看到很多使用自定義UIWindow作爲通知橫幅或自定義AlertView的Pod。但他們並沒有將自定義的UIWindow放在AppDelegate中,而是放在自定義類中。

例如:
這是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類,而不是應用程序的委託裏面,在我的情況,當我把它放在我的自定義類中,它不會出現。它需要在應用程序委託中變量。

如何顯示自定義窗口並將其放入自定義類中?

回答

0

您是否嘗試使用您的窗口內容創建ViewController並設置rootViewController屬性?

+0

我試過了,它沒有出現,除非窗口是AppDelegate類中的全局變量。 –

+0

@EdwardAnthony windowLevel呢?它是否設置爲UIWindowLevelAlert? –

+0

是的,我將它設置爲UIWindowLevelAlert,仍然無法工作。我閱讀這個http://stackoverflow.com/questions/28002992/custom-uiwindow-not-display 它需要是全局變量才能工作。但CRToast將窗口變量放在他的自定義類中。 –