Skip to content

Instantly share code, notes, and snippets.

@michzio
Created May 4, 2020 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michzio/215098278ddb7e9cff721c2e9e852c8e to your computer and use it in GitHub Desktop.
Save michzio/215098278ddb7e9cff721c2e9e852c8e to your computer and use it in GitHub Desktop.
extension KeyboardAvoider {
func keyboardOffsets(isTabBar: Bool = true, offset: CGFloat = 0) -> (total: CGFloat, adjusted: CGFloat) {
let tabBarHeight = isTabBar ? UITabBarController().tabBar.frame.height : 0
let safeAreaHeight = UIApplication.shared.windows.first{ $0.isKeyWindow }?.safeAreaInsets.bottom ?? 0
let totalKeyboardOffset = self.keyboardRect.height
let keyboardOffset = totalKeyboardOffset > 0 ? totalKeyboardOffset - tabBarHeight - safeAreaHeight - offset : 0
return (totalKeyboardOffset, keyboardOffset)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment