0

I've been having a problem with my layout page for an app, I wanted to add some text fields and I have done so but some of them are low to the page of the screen and when I type in the first two fields it is alright but when I get down to the third and fourth and last text field, the keyboard popup covers it and the user is unable to see what they are typing as shown in the picture.

Is there a way to make it so that when the user clicks on a particular text field especially the last three, they can still see what they are typing and not have it blocked as shown in the picture.

Thank you so much for your help :)

Picture that shows text fields

Picture that shows blocked text fields

Danesh
  • 61
  • 1
  • 7

2 Answers2

1

You can use the following libraries which automatically adjust the height of the screen when key board appears.

  1. IQ Key Borad Implementation:- Added the following code in Appdelegate didFinishLaunchingWithOptions IQKeyboardManager.shared.enable = true

Note :- IF you use IQ Keyboard Tool bar will always appear above the keyboard.

  1. TP KeyBoard (To Implement this you should make the class of scroll/TableView/CollectionView to TPkeyboardAvoidingScrollView/TPkeyboardAvoidingTableView/TPkeyboardAvoidingCollectionView)

OR

You should make use of key board Notification to adjust the height contraint.

 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)

//MARK:- Keyboard Notification

  @objc func keyboardWillShow(_ notification:Notification) {
        if let height = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.height {
                selectedImageViewToBottom.constant = height

        }
    }

    @objc func keyboardWillHide(_ notification:Notification) {
        selectedImageViewToBottom.constant = 0
    }
Anuraj
  • 1,242
  • 10
  • 25
0

use NotificationCenter to track keyboard appearing and disappearing.

you can find it on Move textfield when keyboard appears swift.

you can use https://github.com/hackiftekhar/IQKeyboardManager IQKeyboard manager library also, they are doing really nice.