输入框根据键盘显示与隐藏移动位置
2016-03-23 11:08
211 查看
#pragma mark - textFieldDelegate - (void)textFieldDidBeginEditing:(UITextField *)textField{ if (textField == _text2) { [self registerForKeyboardNotifications]; } } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } - (void)registerForKeyboardNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; return; } - (void)removeForKeyboardNotifications{ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } - (void)keyboardWillShow:(NSNotification *) notif { NSDictionary *info = [notif userInfo]; NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey]; CGSize keyboardSize = [value CGRectValue].size; [_scrollView setContentOffset:CGPointMake(_scrollView.contentOffset.x,_scrollView.contentOffset.y + keyboardSize.height + 10) animated:YES]; return; } - (void)keyboardWillHide:(NSNotification *) notif { NSDictionary *info = [notif userInfo]; NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey]; CGSize keyboardSize = [value CGRectValue].size; [_scrollView setContentOffset:CGPointMake(_scrollView.contentOffset.x, _scrollView.contentOffset.y - keyboardSize.height - 10) animated:YES]; return; }
相关文章推荐
- 探索新的Java输入/输出(Java的NIO.2)包
- 4418: [Shoi2013]扇形面积并|二分答案|树状数组
- eclipse中项目为什么会出现红色感叹号?
- Open_tables Opened_tables table_open_cache
- 1.iOS基础控件
- 关于C#中Thread.Join()的一点理解
- wampserver中mysql数据库的空密码怎么修改
- Unity3D在Android和IOS平台上播放视频方法
- 事件冒泡与事件捕获
- 返回一个整数数组中最大子数组的和(补充:输出该子数组)
- Android最佳性能实践(三)——高性能编码优化
- 利用mahout的Bayes算法的文本情感分析
- Laravel artisan 命令工具
- 窗口開啟居中
- java实例化对象的过程
- 日期获取方式
- 图片预加载问题
- win8 &win10系统下Guest 帐号本地主机登录
- Windows Server 2008 R2 实现通过WEB方式修改域账号密码
- Glide 入门到精通之四——图片缩放和调整大小