键盘

来源:互联网 发布:怎么打开微信淘宝链接 编辑:程序博客网 时间:2024/04/30 14:38

在看asihttprequest代码时候,无意发现了关于键盘弹出时遮盖页面显示的解决方案,

解决方法如下:

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

[[self viewsetAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];

[[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

[[NSNotificationCenter defaultCenteraddObserver: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 userInfoobjectForKey:UIKeyboardBoundsUserInfoKey];

#endif

CGRect keyboardBounds;

[keyboardBoundsValue getValue:&keyboardBounds];

UIEdgeInsets e = UIEdgeInsetsMake(00, keyboardBounds.size.height-420);

[[self tableViewsetScrollIndicatorInsets:e];

[[self tableViewsetContentInset:e];

}

恢复正常页面

- (void)keyboardWillHide:(NSNotification *)notification

{

UIEdgeInsets e = UIEdgeInsetsMake(0000);

[[self tableViewsetScrollIndicatorInsets:e];

[[self tableViewsetContentInset:e];

}


0 0
原创粉丝点击