Last active
October 18, 2015 19:23
-
-
Save pingzh/77d13eb7d57552cf9e3c 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
A simple solution is to move view up with constant of keyboard height. | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil); | |
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil); | |
} | |
func keyboardWillShow(sender: NSNotification) { | |
let frame = (sender.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() | |
self.view.frame.origin.y -= frame.height | |
} | |
func keyboardWillHide(sender: NSNotification) { | |
let frame = (sender.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() | |
self.view.frame.origin.y += frame.height | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment