This is regarding the keyboardFrameWillChange notification.
This code worked as expected under Xcode 14.1 With floating_Keyboard = false Tap the textView Full keyboard opens textView moves up to avoid the keyboard
Change to floating keyboard Floating keyboard opens textView moves to home position
Tap the view background to close the keyboard
Tap the textView again Floating keyboard opens txtView remains at home position Change to full keyboard Full keyboard opens textView moves up to avoid the keyboard
With Xcode 14.2 if the keyboard is floating and the textView is firstResponder, and the keyboard is then set back to full keyboard, the floating_Keyboard = false part of the code does not fire. This means the textView remains in the home position even though the full keyboard opens.
Is anybody else experiencing this?
private var floating_Keyboard: Bool = false
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardFrameWillChange), name: NSNotification.Name(rawValue: UIResponder.keyboardWillChangeFrameNotification.rawValue), object: nil)
@objc func keyboardFrameWillChange(notification: NSNotification)
{
let userInfo = notification.userInfo!
let keyBoardBeginRect = userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as! CGRect
let screenBounds = UIScreen.main.bounds
if (keyBoardBeginRect.equalTo(CGRect.zero))
{
print("\(#function) Floating keyboard")
floating_Keyboard = true
if trickPatterFld.isFirstResponder
{
UIView.animate(withDuration: 0.3) { [weak self] in
self?.bottom_Constraint.constant = self!.patter_Bottom_Constraint
self?.view.layoutIfNeeded()
}
}
} else if keyBoardBeginRect.width == screenBounds.width {
print("\(#function) Full keyboard")
floating_Keyboard = false
if trickPatterFld.isFirstResponder
{
UIView.animate(withDuration: 0.3) { [weak self] in
self?.bottom_Constraint.constant = self!.keyboardHeight
self?.view.layoutIfNeeded()
}
}
}
}
func textViewDidBeginEditing(_ textView: UITextView)
{
if textView.tag == 2
{
set_The_Keyboard_Hgt()
if textView.textColor == Theme.current.placeHolderTextColor
{
textView.text = ""
textView.textColor = Theme.current.textColor
}
if floating_Keyboard == false
{
UIView.animate(withDuration: 0.3) { [weak self] in
self?.bottom_Constraint.constant = self!.keyboardHeight
self?.view.layoutIfNeeded()
}
}
} else {
if textView.textColor == Theme.current.placeHolderTextColor
{
textView.text = ""
textView.textColor = Theme.current.textColor
}
}
}