Keyboard Notification UIKit magic.

Dear random Apple UIKit engineer. This is a question for you. Today let's speak about keyboard notifications. In particular, UIResponder.keyboardWillShowNotification and UIResponder.keyboardWillHideNotification. While working with those, I noticed some undocumented behaviour.
First, let me give you some context:

extension UIViewController {
	func registerForKeyboardNotifications() {
		NotificationCenter.default.addObserver(self, selector: #selector(keyboardNotification), name: UIResponder.keyboardWillShowNotification, object: nil)

		NotificationCenter.default.addObserver(self, selector: #selector(keyboardNotification), name: UIResponder.keyboardWillHideNotification, object: nil)
	}
	
	/// Override this method to handle keyboard notifications. 
	@objc func keyboardNotification(_ notification: Notification) { ... }
}

Eventually, I found that latter method with 3 dots has an implicit animation inside it's scope. Here is the [proof.](https://medium.com /uptech-team/why-does-uiresponder-keyboard-notification-handler-animate-10cc96bce372)

Another thing I noticed, is that this property definition is perfectly valid let curve = UIView.AnimationCurve(rawValue: 7)!. The 7 btw comes from UIResponder.keyboardAnimationCurveUserInfoKey as a default value during my tests. So, the enum with 4 possible values (0...3) can be initialized with a value out of enum's cases range. Also, how can I initialize UIView.AnimationOption from 7? I will pollute my OptionSet which I feed to options parameter on UIView.animate(...)

My questions:

  1. Why implicit animation is not documented and can I trust it or it's a subject to change.
  2. Why UIView.AnimationCurve(rawValue: 7)! does not crash.
  3. How can I convert UIResponder.keyboardAnimationCurveUserInfoKey's value into UIView.AnimationOption properly if I don't want to use implicit value.

I don't encroach on UIKit secrets. I just need to know how to work with the API.

Thank you!

Up!

Up again.

up. Also curious in how to override this value.

Claude Code offered these two solutions:

@objc private func reactOnKeyboardShowing() {
    DispatchQueue.main.async {
        UIView.animate(withDuration: 3) { [weak self] in
            self?.rectangleHeightConstraint.constant = 20
            self?.layoutIfNeeded()
        }
    }
}

@objc private func reactOnKeyboardShowing() {
    let animator = UIViewPropertyAnimator(duration: 3, curve: .easeInOut) { [weak self] in
        self?.rectangleHeightConstraint.constant = 20
        self?.layoutIfNeeded()
    }
    animator.startAnimation()
}

But it feels like the animation happens after the keyboard appears, not after it started launching...

Keyboard Notification UIKit magic.
 
 
Q