textField代理相关操作方法
//点击背景关键盘
- (IBAction)BackGround:(id)sender
{
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}
#pragma mark textfield delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
return YES;
}
//textField 弹到指定高度
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect frame = textField.frame;
int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0)+frame.size.height +88;//键盘高度216
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
[UIView setAnimationDuration:animationDuration];
float width = self.view.frame.size.width;
float height = self.view.frame.size.height;
if(offset > 0)
{
CGRect rect = CGRectMake(0.0f, -offset,width,height);
self.view.frame = rect;
}
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height);
self.view.frame = rect;
[UIView commitAnimations];
[textField resignFirstResponder];
}