I\'m trying to understand the new keyboard animation in iOS 7.0 on the iPhone 5 Simulator. I want to resize my UITableView
when the keyboard appears, but I can\
In Swift 4
Add observers for keyboard notifications:
via
NSNotificationCenter.defaultCenter().addObserver(_ observer: Any,
selector aSelector: Selector,
name aName: NSNotification.Name?,
object anObject: Any?)
And implement selector to animate the UI with Keyboard animation. In order to create a valid curve value we need to shift UIResponder.keyboardAnimationCurveUserInfoKey by << 16
func keyboardWillShow(_ notification: Notification!) {
if let info = notification.userInfo {
let keyboardSize = info[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
let duration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
let curveVal = (info[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue ?? 7 // default value for keyboard animation
let options = UIView.AnimationOptions(rawValue: UInt(curveVal << 16))
UIView.animate(withDuration: duration, delay: 0, options: options, animations: {
// any operation to be performed
}, completion: nil)
}
}