Adjust textField (multiple) locations based on the keyboard so that it will not be blocked by the keyboard, textfield Blocking

Source: Internet
Author: User

Adjust textField (multiple) locations based on the keyboard so that it will not be blocked by the keyboard, textfield Blocking

When a textField is displayed on the interface, make sure that the textField is not blocked by the keyboard. The general practice is to listen to UIKeyboardWillShowNotification and UIKeyboardWillHideNotification, obtain the keyboard information through notification. userInfo in the notification selector method, and then adjust the interface location. However, when there are more than two textfields on the interface, the problem arises: when switching between textfields, UIKeyboardWillShowNotification may not be sent! It is observed that the system will send the UIKeyboardWillShowNotification again only when the keyboard size changes... For example, if the numeric keyboard is changed to the English keyboard, the keyboard size remains unchanged, so no notification will be sent. If the English keyboard is changed to the Chinese keyboard, the willShow notification will be sent again. Other similar issues are as follows: there are multiple textfields on the interface, some of which are blocked and some are not blocked. What should I do if I want to move the target textField to an unblocked position every time when switching textField? (The most common logon interface is the account, password, and two textfields. When both fields are entered, they must be moved to the appropriate location .) -(Void) textFieldDidBeginEditing :( UITextField *) When textField is adjusted?If the keyboard does not appear at this time, the method is called before the system sends the UIKeyboardWillShowNotification notification. If the keyboard already appears, the system may not send the UIKeyboardWillShowNotification notification again, at this time, you do not necessarily know the size of the keyboard (and the problem is that the system does not necessarily issue a hair, if it is not, it is better to handle it). If you record the size of the keyboard when the first keyboard appears, when switching textField, the saved size is still used, and the adjusted position may not be correct... If some numeric values are written for this viewController, the problem may have plagued me for a long time when the screen is adapted to a 3.5-inch, 4-inch, 4.7-inch, or 5.5-inch screen, later, I studied the code of github, and found the ideal solution. The third-party library of great gods: TPKeyboardAvoiding IQKeyboardManager Both databases solve the above problems, TPKeyboardAvoiding is a little troublesome and needs to be inherited, IQKeyboardManager is very powerful, but it is relatively complicated. I don't understand how to use IT ()...Therefore, I wrote a database myself and basically solved the above problems. The functions are relatively simple and easy to use. Demo address: https://github.com/Phelthas/LXMKeyboardManager core idea is: 1, with a separate class to save the keyboard related state 2, adjust textField to the appropriate position within the visible range of the screen, instead of sticking to the keyboard (refer to the TPKeyboardAvoiding idea) 3. Use an isKeyboardShow attribute to record whether the keyboard has appeared, and then make different adjustments based on the status. 4, in the selector of the keyboard notification, you only need to process the isKeyboardShow status effects. Currently, scrollView, tableView, collectionView, or textField on the cell can be supported. If you have other requirements, you can add any bugs, discussion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.