Created
August 16, 2016 22:54
-
-
Save RxDx/f23ff4c0d76bd1c301888a31fde60a02 to your computer and use it in GitHub Desktop.
This file contains hidden or 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().addObserver(self, selector: #selector(keyboardWillShow), name:UIKeyboardWillShowNotification, object: nil) | |
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillHide), name:UIKeyboardWillHideNotification, object: nil) | |
func keyboardWillShow(notification:NSNotification){ | |
var userInfo = notification.userInfo! | |
var keyboardFrame:CGRect = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue() | |
keyboardFrame = self.view.convertRect(keyboardFrame, fromView: nil) | |
var contentInset:UIEdgeInsets = self.scrollView.contentInset | |
contentInset.bottom = keyboardFrame.size.height | |
self.scrollView.contentInset = contentInset | |
} | |
func keyboardWillHide(notification:NSNotification){ | |
let contentInset:UIEdgeInsets = UIEdgeInsetsZero | |
self.scrollView.contentInset = contentInset | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment