键盘遮住问题

- (void)textFieldDidBeginEditing:(UITextField *)textField

{

NSLog(@"textFieldDidBeginEditing");

CGRect frame = textField.frame;

CGFloat heights = self.view.frame.size.height;

// 当前点击textfield的坐标的Y值 + 当前点击textFiled的高度 - (屏幕高度- 键盘高度 - 键盘上tabbar高度)

// 在这一部 就是了一个 当前textfile的的最大Y值 和 键盘的最全高度的差值,用来计算整个view的偏移量

int offset = frame.origin.y +42- ( heights -216.0-35.0);//键盘高度216NSTimeInterval 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];

}

/**

*  textField 取消选中状态

*

*/

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

NSLog(@"touchesBegan");

[self.view endEditing:YES];

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

}

还有点击键盘的return键的时候恢复原状就要在

- (BOOL)textFieldShouldReturn:(UITextField *)textField;里头处理。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容