Skip to content

Instantly share code, notes, and snippets.

@amosavian
Created November 1, 2017 10:39
Show Gist options
  • Select an option

  • Save amosavian/bc3cbd122630f2d6e347dd275ac3ed32 to your computer and use it in GitHub Desktop.

Select an option

Save amosavian/bc3cbd122630f2d6e347dd275ac3ed32 to your computer and use it in GitHub Desktop.
@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