当键盘出现时,更新UIView中UITableView的高度



我需要更新UIView中的UITableView高度。

我得到了键盘的高度,当它显示使用以下代码:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
- (void)keyboardDidShow: (NSNotification *) notif{
self.isKeyboardVisible = TRUE;
// Get the size of the keyboard.
CGSize keyboardSize = [[[notif userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
//Given size may not account for screen rotation
int height = MIN(keyboardSize.height,keyboardSize.width);
int width = MAX(keyboardSize.height,keyboardSize.width);
}

但是,如何将表视图的高度更改为刚好在键盘上方?我需要这样做,以便在用户滚动时,uitableview中的所有单元格都可见,而无需关闭键盘。当然,如果用户关闭键盘,那么我应该将uitableview的高度增加回以前的状态。感谢您的帮助。

如果您使用的是obj-c而不使用约束,请查看此解决方案:https://gist.github.com/TimMedcalf/9505416?permalink_comment_id=3256880#gistcomment-3256880

最新更新