IOS tap the screen to get the keyboard down

Source: Internet
Author: User

Believe that a lot of iOS small white and I like, when dealing with keyboard logic will encounter problems, one of the most prominent problem is how to let the keyboard down, without affecting the other buttons and table gestures? In fact, only need to add gesture agent on it, when I found this method, also really makes me happy, because I encountered a lot of keyboard problems in the development, an interface may have a lot of keyboard, and the keyboard type may be different, and some may only need a numeric keypad, Some may need a default keyboard, numeric keypad sometimes input Chinese, back-end processing is abnormal, will error, so let us front-end to limit. If we use the numeric keypad, this time do not want to affect the other gestures, this time we can use this method: (Support does not affect the table of the agent, support the input box of a button to clear, and other buttons of the Click event, do not forget to add gestures proxy)

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (viewtapped:)];

Tap.cancelstouchesinview = NO;

Tap.delegate = self;

[Self.view Addgesturerecognizer:tap];

-(void) viewtapped: (uitapgesturerecognizer*) Tap

{

[Self.view Endediting:yes];

}

-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (Uitouch *) touch{

If Uitableviewcellcontentview (that is, click Tableviewcell), the touch event is not intercepted

if ([Nsstringfromclass ([Touch.view class]) isequaltostring:@ "Uitableviewcellcontentview"] | | [Nsstringfromclass ([Touch.view class]) isequaltostring:@ "Uitextfield"] | | [Nsstringfromclass ([Touch.view class]) isequaltostring:@ "UIButton"]) {

return NO;

}

return YES;

}

IOS tap the screen to get the keyboard down

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.