Skip to content

Instantly share code, notes, and snippets.

@Arrlindii
Created June 22, 2019 19:45
Show Gist options
  • Select an option

  • Save Arrlindii/84b558dd05244afee0621fc80f1eb6ef to your computer and use it in GitHub Desktop.

Select an option

Save Arrlindii/84b558dd05244afee0621fc80f1eb6ef to your computer and use it in GitHub Desktop.
let keyboardWillOpen = NotificationCenter.default
.publisher(for: UIResponder.keyboardWillShowNotification)
.map {$0.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect}
.map {$0.height}
let keyboardWillHide = NotificationCenter.default
.publisher(for: UIResponder.keyboardWillHideNotification)
.map { _ in CGFloat(0)}
_ = Publishers.Merge(keyboardWillOpen, keyboardWillHide)
.subscribe(on: RunLoop.main)
.assign(to: \UIScrollView.contentInset.bottom, on: scrollView)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment