我有一个包含四个部分、总共21行的表视图,其中每个单元格的右侧都包含一个文本字段。
当我试图滚动和编辑表格视图底部的单元格时,我无法将最后四到五个单元格正确地放置在键盘上方。桌子的其余部分放置得很好。
我在textFieldDidBeginEditing:中用moveUp:YES调用过这个方法,在textFieldShouldReturn:中用NO调用过这个方法。
#define kOFFSET_FOR_KEYBOARD 42
-(void)viewMoveUp:(BOOL)moveUp{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGRect rect = self.view.frame;
if (moveUp)
{
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
// revert back to the normal state.
rect.origin.y = 0;
rect.size.height = 360;
}
self.view.frame = rect;
[UIView commitAnimations];
}发布于 2011-11-08 16:56:20
让它变得简单。
使用UITableViewController而不是UIViewController。UITableViewController将为您处理键盘显示时的大小调整。
https://stackoverflow.com/questions/8046445
复制相似问题