1. Input-related optimization issues In most applications, there is a need for input. Faced with many users, their ideas are different, and the text content they input is also strange. Faced with different inputs, how can we optimize the input experience? Here we summarize the input-related issues, mainly as follows: 2. The input box moves with the keyboard There are two ways to build the interface, code or storyboard/xib. These two methods are the same in handling keyboard movement. Here we recommend using a packaged third-party framework: TPKeyboardAvoiding 1. Code processing method rootView uses TPKeyboardAvoidingScrollView in the TPKeyboardAvoiding framework to initialize. For example, the login interface, LoginViewController (inherited from UIViewController), the processing method is as follows:
The code constructs the interface and realizes that the input box moves with the keyboard. The class TPKeyboardAvoidingScrollView needs to be processed as the root view. 2. Storyboard/xib processing method Storyboard/xib is easier to handle, just set the rootView of the view controller to TPKeyboardAvoidingScrollView (1) Select the root view of the controller (2) Setting the default instantiation class #p# 3. Commonly used basic settings 1. Common basic settings Including opening the keyboard, closing the keyboard, specifying the keyboard input type, and specifying the type of the return button, such as the following code
2. Filter input through a proxy Through the UITextField/UITextView proxy, you can control the input more accurately, for example: filter specified characters, prohibit input when the number of characters exceeds the limit, etc. (1) The UITextField code is as follows:
(2) The UITextView code is as follows:
UITextField/UITextView can detect the user input in real time through the proxy method, which is convenient for input constraints. For example, when the input exceeds 10 characters, the user is prohibited from inputting. However, this experience is not good and it is recommended not to use it. #p# 4. Response programming processing, accurate prompt information 1. How to optimize The constraints of input information are generally to directly prompt the rules to the user, for example: the input of user nicknames in social networking:
After the user clicks the OK button, the validity of the input is checked and the user is prompted with information in the form of a dialog box (or HUD) The above processing method is very common and can meet basic needs. However, we no longer use the above design for the following two reasons: In the actual development process, the prompt information is reduced to
When the user actively enters characters such as spaces, carriage returns, punctuation marks, or exceeds the length, the system will automatically prompt the user for information. As shown in the following figure, there is no input, the OK button is disabled, and only very little useful information is prompted. The input is legal, the confirmation button is enabled If the input is illegal, the error is highlighted and the OK button is disabled. 2. Code implementation Using the third-party framework ReactiveCocoa, first implement the function of the prompt below and the picture on the right when the user inputs (do not use the third-party framework, you can implement it yourself through the proxy)
The following functions are implemented: According to the legality of the input, set the enabled property of the button. This step requires downloading the RAC syntax support file. More detailed introduction to Swift support for ReactiveCocoa
#p# 5. Chinese processing method When Chinese characters are input, the above word count check is inaccurate. For example, when 6 characters of "I love Chinese culture" are input through the input method, the number of characters in self.nickTextField.text is 23, and the prompt information is incorrect. UITextView/UITextFiled has a markedTextRange property, which is used to identify whether there is currently selected text (when there is selected text, it is the unfinished input state in the above figure). This principle is used to solve similar problems such as Chinese
VI. Conclusion Input is the most time-consuming operation in mobile apps. If it is not handled properly, it is easy to lose users. Here are some points to summarize: |
<<: On Chance and Skill in Game Design
>>: Is Android controlled by Google not a good Android?
At the beginning of 2022, Xiaohongshu's commu...
Today’s topic is how to ignite social communicati...
"The main data products of the two Fengyun m...
It's quite "bald" Some friends lame...
There are usually two reasons why menstruation ap...
1. Redefine growth 01. Traditional Funnel Model T...
Meitu XiuXiu, which is considered to best represe...
What is server bandwidth? The bandwidth of the se...
01 Did you know that the third new aircraft carri...
August 20 Based on Chinese mythology Action RPG C...
Grandpa Cao is over 60 years old. After retiring ...
According to Japanese media reports, GAC Honda ha...
Everyone knows the banned words in the new advert...
This compiled article mainly introduces the low-c...