Many times when using Uitextfield, handling the keyboard is a tricky issue. Question one: How do I hide my keyboard? Scenario 1. Change the bottom right corner of the keyboard line break (enter) key is the completion key, after the implementation of proxy method keyboard auto Rebound
Keyboardcontroll.gif
Uitextfield *textfield = [[Uitextfield Alloc]initwithframe:CGRectMake (100,300,200,40)]; [Self.view Addsubview:textfield];Textfield.delegate = self;Textfield.returnkeytype =uireturnkeydone;//changes to the finish key, if you import theYytext Frame then the original is replaced and changed to Returnkeytype =uikeyboardtypetwitter;//implementationUitextfield Proxy Method-(BOOL) Textfieldshouldreturn: (uitextfield *) TextField {[TextField resignfirstresponder];//cancel First responder return
Of course, Sogou Input method is the function of the hidden keyboard, but you can not guarantee that each user is equipped with Sogou input method, this scheme will also change the lower right corner of the Sogou keyboard button for the completion of the key
Scenario 2. Click the TextField outside the keyboard to rebound
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES];}
If the TextField on the TableView can also implement the following TableView proxy method
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [self.view endEditing:YES];}
Issue two: Keyboard and keyboard masking input box problems
Solution Solutions
#pragma mark - textFieldDelegate(别忘了遵守协议设置代理)- (void)textFieldDidBeginEditing:(UITextField *)textField { self.view.y = self.view.y - 216; //216是输入框在最底部时view移动的距离,具体移动多少距离,需要根据实际情况而定}- (void)textFieldDidEndEditing:(UITextField *)textField { self.view.y = self.view.y + 216;}
IOS Keyboard Processing (change keyboard for completion key), Uitextfield keyboard display hidden, popup, rebound