Created
November 1, 2017 10:39
-
-
Save amosavian/bc3cbd122630f2d6e347dd275ac3ed32 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
| @objc dynamic func adjustViewForKeyboardNotification(_ notification: Notification) { | |
| guard let notif = (notification.userInfo as NSDictionary?) as? [String: AnyObject] else { return } | |
| guard let keyboardFrame = notif[UIKeyboardFrameEndUserInfoKey]?.cgRectValue, let duration = notif[UIKeyboardAnimationDurationUserInfoKey] as? Double else { | |
| return | |
| } | |
| UIView.beginAnimations(nil, context: nil) | |
| UIView.setAnimationDuration(duration) | |
| if let curve = notif[UIKeyboardAnimationCurveUserInfoKey] as? Int { | |
| UIView.setAnimationCurve(UIViewAnimationCurve(rawValue: curve)!) | |
| } | |
| UIView.setAnimationBeginsFromCurrentState(true) | |
| var inset = tableView.contentInset | |
| if notification.name == .UIKeyboardWillShow { | |
| inset.bottom = keyboardFrame.height | |
| } else { | |
| inset.bottom = 0 | |
| } | |
| tableView.contentInset = inset | |
| UIView.commitAnimations() | |
| if let row = cells.index(of: .notes) { | |
| tableView.scrollToRow(at: IndexPath(row: row, section: 0), at: UITableViewScrollPosition.bottom, animated: true) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment