iOS keyboard height returned incorrectly on UIKeyboardWillShowNotification/
Maybe you are using a tab bar controller, if yes, then when u margin the view after keyboard was shown, calculate the margin bottom without tab bar height.
You can find the tab bar height using:
self.tabBarController?.tabBar.frame.height