ios不比android,没返回键,需要自己隐藏键盘,下面是我常用的方法,分享给大家
textfile开始编辑事件为“Editing did Begin” ,结束事件为“Did end on exit”
方法一
- (IBAction)exitKeyboard:(id)sender { [sender resignFirstResponder]; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:0.30f]; CGRect frame = self.view.frame; frame.origin.y +=216; frame.size. height -=216; self.view.frame = frame; [UIView commitAnimations];}- (IBAction)editBegin:(id)sender { [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:0.30f]; CGRect frame = self.view.frame; frame.origin.y -=216; frame.size.height +=216; self.view.frame = frame; [UIView commitAnimations];}
方法二
-(IBAction) slideFrameUp{ [self slideFrame:YES];}-(IBAction) slideFrameDown{ [self slideFrame:NO];}-(void) slideFrame:(BOOL) up{ const int movementDistance = 60; // tweak as needed const float movementDuration = 0.3f; // tweak as needed int movement = (up ? -movementDistance : movementDistance); [UIView beginAnimations: @"anim" context: nil]; [UIView setAnimationBeginsFromCurrentState: YES]; [UIView setAnimationDuration: movementDuration]; self.view.frame = CGRectOffset(self.view.frame, 0, movement); [UIView commitAnimations];}
注,此方法,如果用navigationViewController push到下一View的时候,需要 添加下面代码,将textfiled的状态取消,否则pop回来时候,view的未知会有问题,或者键盘不隐藏
[tfPwd resignFirstResponder]; [tfAccount resignFirstResponder];