[iOS]解决键盘弹出时挡住输入框的问题
来源:互联网 发布:矩阵分析引论视频 编辑:程序博客网 时间:2024/05/21 16:46
做ios的时候总会遇到这样打问题:用户点了文本输入框之后键盘遮挡住了原来输入的位置。
为了解决这个问题,具体需要一下几步:
1.给当前的UIViewController添加委托
@interface SignupViewController : UIViewController<UITextFieldDelegate>
2.在xib或storyboard里面将textfield的delegate与controller相连
3.在m文件里实现委托的方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField { // When the user presses return, take focus away from the text field so that the keyboard is dismissed. 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]; return YES; }- (void)textFieldDidBeginEditing:(UITextField *)textField{ CGRect frame = textField.frame; int offset = frame.origin.y + frame.size.height - (self.view.frame.size.height - 216.0);//键盘高度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]; }
1 0
- [iOS]解决键盘弹出时挡住输入框的问题
- IOS TextField弹出键盘挡住输入框的问题
- IOS TextField弹出键盘挡住输入框的问题(续)
- iOS 解决键盘挡住输入框的问题
- IOS 解决键盘挡住输入框的问题
- iOS 解决键盘挡住输入框的问题
- IOS 解决键盘挡住输入框的问题
- IOS 解决键盘挡住输入框的问题
- iOS 解决键盘挡住输入框的问题
- IOS 解决键盘挡住输入框的问题
- ios 解决键盘挡住输入框的问题
- IOS解决键盘挡住输入框的问题
- 解决键盘挡住输入框的问题
- 关于键盘弹出挡住输入框的问题
- ios解决键盘挡住输入框的方法
- 客户端登录界面,根据输入框的弹出改变界面样式,解决键盘挡住输入框的问题
- 解决虚拟键盘挡住了输入框的问题
- 解决输入框被键盘挡住的问题
- poj 2418
- 【USACO 2013 February Gold】分割农场
- DIV+CSS圆角边框
- 说说真实的心里话吧
- java interface 介绍
- [iOS]解决键盘弹出时挡住输入框的问题
- 求大神赐教严重: Error configuring application listener of class org.springframework.web.context.ContextLoad
- Leetcode: Search Insert Position
- 黑马程序员—静态与非静态、构造函数
- 第17周项目19-数组用于进制转换
- 深入Android通过Apache HTTP访问HTTP资源
- ubuntu常用PPA
- 【stagefrightplayer】5 音频输出AudioPlayer介绍
- 生产环境下hadoop集群配置之awk生成hadoop拷贝脚本