Last active
April 12, 2016 14:02
-
-
Save RichFell/fd389b1641c0b3a5fca9 to your computer and use it in GitHub Desktop.
Keyboard Change Frame Notification
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
NSNotificationCenter.defaultCenter().addObserverForName(UIKeyboardWillChangeFrameNotification, object: nil, queue: nil) { (notification) -> Void in | |
guard let info: [NSObject: AnyObject] = notification.userInfo, | |
let keyboardFrameValue = info[UIKeyboardFrameEndUserInfoKey] as? NSValue, | |
let duration = info[UIKeyboardAnimationDurationUserInfoKey] as? Int else { | |
return | |
} | |
let diff = CGRectGetHeight(keyboardFrameValue.CGRectValue()) | |
UIView.animateWithDuration(Double(duration), animations: { () -> Void in | |
self.view.frame = CGRect(x: self.view.frame.minX, y: keyboardFrameValue.CGSizeValue().height, width: self.view.frame.width, height: self.view.frame.height) | |
self.view.layoutIfNeeded() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment