Ios 为什么在swift中点击推送通知并移动ViewController时状态栏消失
上面的代码是获取推送通知数据,并在用户点击时发送给相关的视图控制器。但我发现当视图控制器打开时,状态栏丢失。请告诉我如何修理,谢谢 乍一看(在没有实际验证代码的情况下),我怀疑罪魁祸首是:Ios 为什么在swift中点击推送通知并移动ViewController时状态栏消失,ios,swift,swift3,Ios,Swift,Swift3,上面的代码是获取推送通知数据,并在用户点击时发送给相关的视图控制器。但我发现当视图控制器打开时,状态栏丢失。请告诉我如何修理,谢谢 乍一看(在没有实际验证代码的情况下),我怀疑罪魁祸首是: func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escapi
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()
}
}
}
您正在将窗口设置为覆盖视图的全部边界。要查看这是否是问题所在,只需将该行更改为以下内容:
self.window = UIWindow(frame: UIScreen.main.bounds)
看看问题是否消失了。在我的代码中,我只是简单地更改了窗口的顶部位置以允许状态栏。您是否尝试过此设置,方法是-首选StatusBarHidden为not working,尽管它看起来不如占用更多的空间,因为导航栏的高度比正常值大。
var rect = UIScreen.main.bounds
rect.origin.y += 20
self.window = UIWindow(frame: rect)