This happens with
keyboardView.heightAnchor.constraint(equalToConstant: 50).isActive = true
keyboardView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
keyboardView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
keyboardView.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor).isActive = true
as well.
When you scroll to dismiss, it snaps back to the keyboard and is sticky. But until you reach the bottom, there is a gap and it doesn't follow on dismiss until hitting the bottom