TextView键盘输入 弹出指定高度 点击return收回虚拟键盘

来源:互联网 发布:淘宝店最高等级是什么 编辑:程序博客网 时间:2024/04/30 08:11


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];}


0 0
原创粉丝点击