我有一张桌子,下面是他们的底视图。我的目标是在键盘输出时向上移动。但是当我们调整键盘时,这种方法会向上调用我的底部视图。我被困了
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
keyBoadSize =kbSize.height;
[UIView animateWithDuration:0.2f animations:^{
CGRect frame=bottomView.frame;
keyBoardHeight = keyBoadSize;
frame.origin.y -=keyBoadSize;
bottomView.frame=frame;
frame = tableViews.frame;
frame.size.height -= keyBoardHeight;
tableViews.frame = frame;
}
我也在使用
- (void)textViewDidChange:(UITextView *)textView
{
CGFloat fixedWidth = textView.frame.size.width;
CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
textView.frame = newFrame;
CGRect frame1 = [UIScreen mainScreen].bounds;
bottomView.frame=CGRectMake(0, frame1.size.height-keyBoardHeight-20-newSize.height, self.view.frame.size.width, newSize.height+50);
}
答案 0 :(得分:0)
您需要先在表格视图中添加空格以允许滚动:
[self.tableView setContentInset:UIEdgeInsetsMake(0.0, 0.0, keyBoardheight, 0.0)];
然后设置自定义底部视图的Y位置。
作为旁注,您的示例代码keyBoadSize
具有误导性。它应该是keyBoardheight
。
PS:当键盘解除时,不要忘记重置滚动空间:[self.tableView setContentInset:UIEdgeInsetsZero];
。