显示或隐藏键盘改变tableView高度
2012-11-30 11:06
357 查看
- (void)registerKeybordNotification
{
NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
[notification removeObserver:self];
[notification addObserver:self
selector:@selector(showKeyboard:)
name:UIKeyboardWillShowNotification
object:nil];
[notification addObserver:self
selector:@selector(hideKeyboard:)
name:UIKeyboardWillHideNotification
object:nil];
#ifdef __IPHONE_5_0
// 5.0以上系统中文键盘高度与4.0系统不一样
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 5.0) {
[notification addObserver:self
selector:@selector(showKeyboard:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
}
#endif
}
- (void)showKeyboard:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
CGFloat height = CGRectGetHeight(self.view.frame) - self.barHeight - keyboardHeight;
/* 使用动画效果,过度更加平滑 */
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
{
CGRect rect = _tableView.frame;
rect.size.height = height;
_tableView.frame = rect;
}
[UIView commitAnimations];
}
- (void)hideKeyboard:(NSNotification *)notification
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
{
CGRect rect = _tableView.frame;
rect.size.height = CGRectGetHeight(self.view.frame) - self.barHeight;
_tableView.frame = rect;
}
[UIView commitAnimations];
}
{
NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];
[notification removeObserver:self];
[notification addObserver:self
selector:@selector(showKeyboard:)
name:UIKeyboardWillShowNotification
object:nil];
[notification addObserver:self
selector:@selector(hideKeyboard:)
name:UIKeyboardWillHideNotification
object:nil];
#ifdef __IPHONE_5_0
// 5.0以上系统中文键盘高度与4.0系统不一样
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 5.0) {
[notification addObserver:self
selector:@selector(showKeyboard:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
}
#endif
}
- (void)showKeyboard:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]);
CGFloat height = CGRectGetHeight(self.view.frame) - self.barHeight - keyboardHeight;
/* 使用动画效果,过度更加平滑 */
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
{
CGRect rect = _tableView.frame;
rect.size.height = height;
_tableView.frame = rect;
}
[UIView commitAnimations];
}
- (void)hideKeyboard:(NSNotification *)notification
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
{
CGRect rect = _tableView.frame;
rect.size.height = CGRectGetHeight(self.view.frame) - self.barHeight;
_tableView.frame = rect;
}
[UIView commitAnimations];
}
相关文章推荐
- iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
- iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
- 显示或隐藏键盘改变tableView高度
- 动态改变tableHeaderView的显示隐藏及高度
- tableviewcell 自动调整textfiled的键盘遮挡问题 UITableViewController中的tableview做可以自适应键盘高度来改变tableview的额外高度。
- UIScrollView中UITextField文本编辑框位置随键盘的显示(隐藏)改变
- iOS 输入框弹出键盘后改变tableView高度内容不被遮挡
- 改变tableHeaderView的高度
- iOS:自定义导航栏,随着tableView滚动显示和隐藏
- iOS tableView滑动隐藏/显示tabbar
- iOS开发中如何在键盘弹出时改变View的高度
- ios swift开发中,使用键盘,tableview根据键盘调整高度
- [iOS]在tableview中用动画效果改变cell的高度
- 改变navigationbar 高度, 并且让tableview的cell 不被覆盖
- ios开发笔记之如何让tableView根据文本内容动态改变cell的高度
- 【笔记】 改变 tableHeaderView 高度
- 获得键盘高度以及UITableView中多个UITextField时UITableView的滚动和键盘的隐藏
- tableview Group的使用-section Header的高度显示一致
- iOS开发--改变tableHeaderView的高度
- 在tableView中添加webView显示商品图文详情 自适应高度