ios - 自定义 UIWindow 不显示

标签 ios objective-c swift uikit 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 时才会出现。

我看到许多 Pod 将自定义 UIWindow 用于通知横幅或自定义 AlertView。但是他们没有将自定义 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 类中,而不是应用程序委托(delegate)中,在我的情况下,当我将它放在我的自定义类中时,它不会出现。它需要在应用程序委托(delegate)中可变。

如何显示自定义窗口并将其放入自定义类中?

最佳答案

您是否尝试过使用您的窗口内容创建一个 ViewController 并设置 rootViewController 属性?

关于ios - 自定义 UIWindow 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31892487/

相关文章:

ios - 我如何获得 Alamofire get-request 的 location-header?

ios - 快速从对象数组中删除对象

ios - 如何在 iOS 上禁用 firestore 的持久性(缓存)

ios - UITableView:通过拖放将单元格移动到另一个位置

ios - 解析未检索到或未在 UITableView 中显示的对象

iphone - iOS 7 动态模糊效果,如控制中心

ios - bitcode 是否支持弱链接第三方框架?

objective-c - 如何在没有死锁的情况下同步调度主队列?

ios - 全屏 PushViewController

ios - dyld:Xcode 更新后未加载库:@rpath/libswiftCore.dylib