ios键盘高度监听
2016-03-08 16:06
447 查看
- (void)keyboardNotifiation{ //注册键盘出现的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil]; //键盘变化 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil]; //键盘退出 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil]; } - (void)keyboardWasShown:(NSNotification *)notification{ } - (void)keyboardWillChange:(NSNotification *)notification{ NSDictionary *info = [notification userInfo]; CGRect beginKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y; CGPoint offset = self.tableView.contentOffset; if (yOffset < 0) { offset.y -= yOffset; if (offset.y < 0) { offset.y = 0; } } [self.tableView setContentOffset:offset animated:YES]; } - (void)keyboardWillBeHidden:(NSNotification *)notification{ }注意 添加了观察者就必须有对应的触发方法,虽然为空,不能不写
相关文章推荐
- iOS 强引用(__strong)和弱引用(__weak)浅析
- iOS ARC下内存泄露 注意点
- iOS学习历程图
- 【iOS】星星评分控件HGDQStars
- IOS等比率缩放图片 工具function
- [iOS]制作静态库
- JS判断客户端是否是iOS或者Android
- iOS runtime基础知识
- iOS url schemes应用
- iOS中获取各种文件的目录路径的方法
- iOScell 重用解决办法
- iOS Block循环引用精讲
- iOS 图片压缩
- iOS开发—巧用反射机制
- iOS svn配置
- 手机号正则表达式iOS
- iOS项目开发中遇到CRASH:重写Setter对服务器获取的数据做空值的过滤处理
- iOS CGAffineTransform属性
- nagios 安装配置(包含nrpe端)全 (三)
- iOS开发笔记--iOS之轻松上手block