Created
March 6, 2018 10:55
-
-
Save OscarApeland/a03ce965082d3e8e958e37cc71f45379 to your computer and use it in GitHub Desktop.
How to offset and animate something that hovers above the keyboard with auto layout constraints
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
NotificationCenter.default.addObserver(forName: .UIKeyboardWillChangeFrame, object: nil, queue: .main) { [weak self] (notification) in | |
guard let strongSelf = self, | |
let targetFrame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect, | |
let animationCurve = notification.userInfo?[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber, | |
let animationDuration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber else { | |
return | |
} | |
strongSelf.view.layoutIfNeeded() | |
strongSelf.proceedButtonBottomConstraint.constant = -UIScreen.main.bounds.intersection(targetFrame).height | |
UIView.animate(withDuration: TimeInterval(truncating: animationDuration), delay: 0.0, | |
options: UIViewAnimationOptions(rawValue: UInt(truncating: animationCurve)), | |
animations: strongSelf.view.layoutIfNeeded, | |
completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment