如何在键盘出现时滚动表格,以适应输入框的显示
2015-12-03 12:55
399 查看
[objc] view plaincopyprint?
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
//
- (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)keyboardWillShow:(NSNotification *) notif {
NSDictionary *info = [notif userInfo];
NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
[_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,
_tableView.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;
[_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,
_tableView.contentOffset.y - keyboardSize.height - 10)
animated:YES];
return;
}
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
//
- (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)keyboardWillShow:(NSNotification *) notif {
NSDictionary *info = [notif userInfo];
NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [value CGRectValue].size;
[_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,
_tableView.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;
[_tableView setContentOffset:CGPointMake(_tableView.contentOffset.x,
_tableView.contentOffset.y - keyboardSize.height - 10)
animated:YES];
return;
}
相关文章推荐
- Linux学习笔记(四、目录处理命令)
- SVN中trunk,branches,tags用法详解
- sql 根据经纬度求距离
- linux screen 命令详解
- lpxelinux启动linux
- The C++ Standard Library: shared_ptr and unique_ptr
- C、c++ .h 头文件的作用
- 01背包 的简述
- Android startActivityForResult(intent, requestCode)的用法。
- 支付清算体系介绍及案例说明
- VS2010安装部署成.NET 2.0过程的几个问题(转)
- kafka+zookeeper环境配置(Mac 或者 linux环境)
- CodeForces - 27E Number With The Given Amount Of Divisors (反素数入门)
- ubuntu下Qt cannot find -lGL错误的解决方法
- grep在文本中查找内容
- aText使用技巧:故障排除与自动更正拼写
- iOS开发之多媒体API
- jsp include指令元素
- XmlPullParser解析xml文件(还原短信)
- CentOS6.5+Puppet3.7.3 安装、配置及测试