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