ios - 为什么当我点击推送通知并快速移动 ViewController 时状态栏消失

标签 ios swift swift3

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    /* */
    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.rootViewController = UIViewController()
    self.window?.windowLevel = UIWindowLevelAlert + 1
    self.window?.makeKeyAndVisible()

    /*

    fetch and add push notification data

     */
    goAnotherVC()
}

func goAnotherVC() {
    if (application.applicationState == UIApplicationState.active) {
        /* active stage is working */ 
    } else if (application.applicationState == UIApplicationState.inactive || application.applicationState == UIApplicationState.background) {
        if (type == "1" || type == "2") {
            let storyboard: UIStoryboard = UIStoryboard(name: "MyAppointments", bundle: nil)
            let apptVC = storyboard.instantiateViewController(withIdentifier: "NotificationDetailViewController") as! NotificationDetailViewController
            let navigationController = UINavigationController.init(rootViewController: apptVC)
            self.window?.rootViewController = navigationController
            self.window?.makeKeyAndVisible()
        } else if (type == "3") {
            let storyboard: UIStoryboard = UIStoryboard(name: "MyAppointments", bundle: nil)
            let apptVC = storyboard.instantiateViewController(withIdentifier: "NotificationDetailViewController") as! NotificationDetailViewController
            let navigationController = UINavigationController.init(rootViewController: apptVC)
            self.window?.rootViewController = navigationController
            self.window?.makeKeyAndVisible()
        } else if (type == "4") {
            let storyboard: UIStoryboard = UIStoryboard(name: "Enquiry", bundle: nil)
            let enqVC = storyboard.instantiateViewController(withIdentifier: "EnquiryDetailViewController") as! EnquiryDetailViewController
            let navigationController = UINavigationController.init(rootViewController: enqVC)
            self.window?.rootViewController = navigationController
            self.window?.makeKeyAndVisible()
        }
    }
}

以上代码是获取推送通知数据,并在用户点击时发送到相关的 View Controller 。但是我发现当 View Controller 打开时状态栏丢失了。请告诉我如何解决它,谢谢。

enter image description here

最佳答案

乍一看(并没有实际验证代码)我怀疑罪魁祸首是这样的:

self.window = UIWindow(frame: UIScreen.main.bounds)

您正在设置窗口以覆盖 View 的整个边界。要查看这是否是问题所在,只需将该行更改为以下内容:

var rect = UIScreen.main.bounds
rect.origin.y += 20
self.window = UIWindow(frame: rect)

然后看看问题是否消失了。在我的代码中,我只是更改了窗口的顶部位置以允许状态栏。

关于ios - 为什么当我点击推送通知并快速移动 ViewController 时状态栏消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42941877/

相关文章:

ios - swift multilpe pickerView

ios - 如何在后台下载后将属性传递给 swift 3 urlsession didFinishDownloadingTo 委托(delegate)?

ios - 淡化标签文本的结尾

android - AWS DynamoDB 扫描在 iOS 上失败但在 Android 上运行

ios - 符合自定义协议(protocol)的通用函数 - Swift

ios - 对标准附件 View 的约束

ios - swift3 playground 无法获取路径的沙箱扩展

ios - 在不自动调整大小的情况下确定 UIView 容器大小

ios - 非官方 API - 访问其他应用程序包和图标 - iOS

swift - 在 Swift 3 中转换 Objective C 谓词