IOS中输入框被软键盘遮挡的解决办法
2015-11-22 19:27
337 查看
//开始编辑输入框的时候,软键盘出现,执行此事件 -(void)textFieldDidBeginEditing:(UITextField *)textField { CGRect frame = textField.frame; int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0);//键盘高度216 NSTimeInterval animationDuration = 0.30f; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; //将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示 if(offset > 0) self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height); [UIView commitAnimations]; } //当用户按下return键或者按回车键,keyboard消失 -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } //输入框编辑完成以后,将视图恢复到原始状态 -(void)textFieldDidEndEditing:(UITextField *)textField { self.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); }
相关文章推荐
- iOS 7应用开发公开课笔记 L13:Core Data and Table View
- ios 通知机制
- iOS 7应用开发公开课笔记 L12:Documents and Core Data
- iOS 7应用开发公开课笔记 L11:Table View and iPad
- iOS 7应用开发公开课笔记 L10:Multithreading, Scroll View
- iOS 7应用开发公开课笔记 L9:Animation and Autolayout
- iOS 7应用开发公开课笔记 L8:Protocols, Blocks, and Animation
- iOS 7应用开发公开课笔记 L7:Views and Gestures
- iOS 7应用开发公开课笔记 L4:Foundation and Attributed Strings
- iOS - 推送
- 现有iOS设备
- iOS---限制文本框输入的长度
- ios的crash分析工具
- iOS中的隐式动画
- 周末了,给iOS开发的孩子们的鸡汤——阿飞
- iOS开发41-XMPP和XAMPP的简介
- 修改mjextension使用一键归档在iOS9下有一定几率会闪退的bug
- POST
- NSURLSession/AFN框架知识点
- AFN框架须知笔记