Last active
September 9, 2015 00:24
-
-
Save macu/e2408971f7f67678eda2 to your computer and use it in GitHub Desktop.
WIP and has a bug
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
| // ... | |
| override func viewDidLoad() | |
| { | |
| super.viewDidLoad() | |
| // Thanks http://stackoverflow.com/a/27665207 | |
| NSNotificationCenter.defaultCenter().addObserverForName( | |
| UIKeyboardWillChangeFrameNotification, | |
| object: nil, | |
| queue: nil, | |
| usingBlock: { notification in | |
| let userInfo = notification.userInfo! | |
| let animationDuration = userInfo[UIKeyboardAnimationDurationUserInfoKey]!.doubleValue | |
| let animationCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey]!.unsignedIntValue | |
| let frameEnd = userInfo[UIKeyboardFrameEndUserInfoKey]!.CGRectValue() | |
| let convertedFrameEnd = self.view.convertRect(frameEnd, fromView: nil) | |
| let keyboardChopsBottom = max(0, self.view.frame.height - convertedFrameEnd.origin.y) | |
| println("keyboard covers bottom \(keyboardChopsBottom) of view") | |
| UIView.animateWithDuration( | |
| animationDuration, | |
| delay: 0, | |
| options: UIViewAnimationOptions(UInt(animationCurve)), | |
| animations: { | |
| self.view.layoutIfNeeded() | |
| }, | |
| completion: nil | |
| ) | |
| } | |
| ) | |
| } | |
| override func viewWillDisappear(animated: Bool) | |
| { | |
| super.viewWillDisappear(animated) | |
| NSNotificationCenter.defaultCenter().removeObserver(self) | |
| } | |
| // ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment