热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

UITextView及UITextField处理键盘弹出视图上移

#pragma-markUITextViewDelegate-(void)textViewDidEndEditing:(UITextView*)textView{
#pragma -mark UITextView Delegate
- (void)textViewDidEndEditing:(UITextView *)textView{
//输入框编辑完成,视图恢复到原始状态
self.view.frame = CGRectMake(0, 0, ScreenW, ScreenH);
}
-(void)textViewDidBeginEditing:(UITextView *)textView{

CGRect frame = textView.frame;

//在这里我多加了62,(加上了输入中文选择文字的view高度)这个依据自己需求而定
int offset = (frame.origin.y+62)-(ScreenH-216.0);//键盘高度216

[UIView beginAnimations:@"ResizeForKeyboard" context:nil];

[UIView setAnimationDuration:0.30f];//动画持续时间

if (offset>0) {
//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示
self.view.frame = CGRectMake(0.0f, -offset, ScreenW, ScreenH);
}
[UIView commitAnimations];
}
//UITextField 同理
#pragma -mark UITextField Delegate
-(void)textFieldDidBeginEditing:(UITextField *)textField{
}

推荐阅读
author-avatar
mobiledu2502882663
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有