您的位置:首页 > 其它

关于键盘弹出时遮盖页面显示的解决方案

2012-11-19 10:40 351 查看
在看asihttprequest代码时候,无意发现了关于键盘弹出时遮盖页面显示的解决方案,

解决方法如下:

在viewload方法里面注册监听键盘弹出和hide

[[self
view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];

然后在keyboardWillShow修改页面的大小- 键盘的高度

- (void)keyboardWillShow:(NSNotification *)notification
{
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
#else
NSValue *keyboardBoundsValue = [[notification
userInfo] objectForKey:UIKeyboardBoundsUserInfoKey];
#endif
CGRect keyboardBounds;
[keyboardBoundsValue getValue:&keyboardBounds];
UIEdgeInsets e =
UIEdgeInsetsMake(0, 0, keyboardBounds.size.height-42,
0);
[[self
tableView] setScrollIndicatorInsets:e];
[[self
tableView] setContentInset:e];
}
恢复正常页面
- (void)keyboardWillHide:(NSNotification *)notification
{
UIEdgeInsets e =
UIEdgeInsetsMake(0,
0, 0,
0);
[[self
tableView] setScrollIndicatorInsets:e];
[[self
tableView] setContentInset:e];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐