简体   繁体   中英

How do I get the status bar height in a third party keyboard? (iOS)

I'm making a keyboard for iOS and need to detect when the status bar changes height in order to be able to update my keyboard accordingly (ie when the user gets a call). Unfortunately, UIApplication.sharedApplication() is not available in third party extensions and I am unable to get the height this way. Is it possible to grab it in any other way? Thanks!

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let navigationController: UINavigationController = .init()
    view.addSubview(navigationController.view)

    let statusBarHeight = navigationController.view.readableContentGuide.layoutFrame.origin.y

    print(statusBarHeight) // 44.0 (iPhone X) / 20.0 (iPhone SE)

    navigationController.view.removeFromSuperview()
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM