iOS Development line of code series: line up the input box

Source: Internet
Author: User

Recently summed up the development process commonly used in the function, found that sometimes I am doing repetitive work. Then decided to take the usual functions out, convenient for the next use.

My idea is to solve the problem with the least amount of code. So write some commonly used tool class, the name is called a line of code series it ... It seems to be quite lame.

The general contents are:

1, a line to fix the input box

2, a line to solve the network request

3, a row to fix up and down refresh (will automatically determine whether the pull or pull down or both coexist)

4, a row of the database (recently write, the function has been basically implemented)

5, a row to save the picture

6, a line to fix the positioning

7, a line to deal with network conditions change

8, a row of X (small collection of functions)



Line up the input box

Input box often see, especially when you need to fill out a lot of information, this time there will be 2 questions: the input box is blocked by the keyboard, how the keyboard disappears.

At that time, considering that one situation is: all the input boxes are not siblings, that is, multiple views nested, then there are n input boxes, the input box may be uitextfield,uitextview,uisearchbar. So in accordance with this situation wrote down, as to the middle of the bug, we can propose changes.

Because the personal limitations are too big, or want everyone to fork and modify, so that other people can also use the tools you write, do not engage in technical monopoly and so on.

Principle: Traverse the sub-view from the relative root view, if the child view is Uitextfield,uitextview,uisearbar, set its Inputaccessoryview to Global toolbar, write down its relative coordinates, and so on.

Use: Using a single line of code, it will automatically determine the coordinates, and you can control how the keyboard disappears: Click the view disappears, or click somewhere outside the keyboard disappears, or click Finish disappears.


-(void) viewdidload {    [super viewdidload];        [Inputhelper SetupInputHelperForView:self.view withdismisstype:inputhelperdismisstypetapgusture];    }



#import <Foundation/Foundation.h> #import <uikit/uikit.h>typedef ns_enum (Nsinteger, Inputhelperdismisstype) {        Inputhelperdismisstypenone = 0,    inputhelperdismisstypecleanmaskview,    Inputhelperdismisstypetapgusture}; @interface inputhelper:nsobject+ (Inputhelper *) sharedinputhelper;-(void) dismissinputhelper;-(void) Setupinputhelperforview: (UIView *) View Withdismisstype: (Inputhelperdismisstype) Dismisstype; @end # define Inputhelper [Inputhelper Sharedinputhelper]



Type of support:

3 types of Uitextfield,uitextview,uisearbar are supported. The usual is OK.


Source:

Click here or point me


iOS Development line of code series: line up the input box

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.