自定义一个UIWindow没有显示
问题描述:
创建自定义窗口自定义一个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类,而不是应用程序的委托里面,在我的情况,当我把它放在我的自定义类中,它不会出现。它需要在应用程序委托中变量。
如何显示自定义窗口并将其放入自定义类中?
答
您是否尝试使用您的窗口内容创建ViewController并设置rootViewController属性?
我试过了,它没有出现,除非窗口是AppDelegate类中的全局变量。 –
@EdwardAnthony windowLevel呢?它是否设置为UIWindowLevelAlert? –
是的,我将它设置为UIWindowLevelAlert,仍然无法工作。我阅读这个http://stackoverflow.com/questions/28002992/custom-uiwindow-not-display 它需要是全局变量才能工作。但CRToast将窗口变量放在他的自定义类中。 –