Skip to content

Instantly share code, notes, and snippets.

@AndreyAnt
Created September 11, 2020 21:10
Show Gist options
  • Save AndreyAnt/d013be38f7b001b3fbc6bcddae5ea2df to your computer and use it in GitHub Desktop.
Save AndreyAnt/d013be38f7b001b3fbc6bcddae5ea2df to your computer and use it in GitHub Desktop.
var keyboardHeight: CGFloat {
let windows = UIApplication.shared.windows
guard let keyboardWindowClass = NSClassFromString("UIRemoteKeyboardWindow"),
let keyboardWindow = windows.first(where: { $0.isKind(of: keyboardWindowClass) }),
let rootViewController = keyboardWindow.rootViewController,
let keyboardViewClass = NSClassFromString("UIInputSetHostView"),
let keyboardView = rootViewController.view.subviews.first(where: { $0.isKind(of: keyboardViewClass) }) else { return 0 }
return keyboardView.frame.height
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment