Created
May 4, 2020 17:36
-
-
Save michzio/215098278ddb7e9cff721c2e9e852c8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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