输入框被键盘遮挡问题
2015-09-06 20:21
357 查看
//开始编辑输入框的时候,软键盘出现,执行此事件
-(void)textFieldDidBeginEditing:(UITextField *)textField{
CGRect frame = textField.frame;
int offset = frame.origin.y + 100 - (Height - 360.0);//键盘高度
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示
if(offset > 0){
self.view.frame = CGRectMake(0.0f, -offset, Width, Height);
}[UIView commitAnimations];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{//触摸隐藏键盘
[self.view endEditing:YES];
[super touchesBegan:touches withEvent:event];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {//按“完成”隐藏键盘
[textField resignFirstResponder];//隐藏输入键盘
return YES;
}
//输入框编辑完成以后,将视图恢复到原始状态
-(void)textFieldDidEndEditing:(UITextField *)textField{
self.view.frame =CGRectMake(0, 0, Width, Height);
}
相关文章推荐
- Oracle常用总结
- leetcode:Reorder List
- android Activity生命周期
- struts2(三)---struts2中的服务端数据验证框架validate
- dbms_stats.gather_table_stats与analyze table 的区别[转贴]
- struts2(三)---struts2中的服务端数据验证框架validate
- 论文搜索 必知one
- C++基础2-类
- SG函数模板
- 优化Android Studio/Gradle构建(转自黑马程序员)
- 16->联机重做日志文件
- matlab与vs2010的匹配过程
- hdu 4722 Good Numbers(找规律,记忆化搜索,数位dp)
- Windows 2008 R2 终端服务器授权安装配置
- Lua:几个名词,Lua、JIT、LuaJIT
- 线性结构(一) - 数组、单链表和双链表
- iOS之旅--依赖管理工具CocoaPods 使用
- 动态规划求解矩阵计算的最优顺序.
- zzuli OJ 1093: 验证哥德巴赫猜想(函数专题)
- android控件之Fragment(碎片)