UITableView获取滚动的偏移:
NSLog(@"tableView滚动纵坐标%f",cardTableView.contentOffset.y);键盘挡住了要输入的view时候,改变view的纵坐标使其适应输入:
//
//将键盘推出时候,view重新回到原来位置
//
-(void)viewKeyboardDisappearChangeRect {
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//把view设置回默认的Rect
CGRect rect = CGRectMake(0.0, 0, self.view.frame.size.width, self.view.frame.size.height);
self.view.frame = rect;
//cardTableView.frame = rect;
[UIView commitAnimations];
}
//
//view要往上推
//@offset:要推的高度偏移
//
-(void)viewKeyboardAppearChangeRect:(int)offset {
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:0.30f];
float width = self.view.frame.size.width;
float height = self.view.frame.size.height;
if (offset > 0) {
//self.view.frame = CGRectMake(0, -offset, width, height);
self.view.frame = CGRectMake(0, -offset, width, height);
}
[UIView commitAnimations];
}
本文介绍了如何使用UITableView处理键盘弹出导致的布局变化问题。通过调整view的位置来避免被键盘遮挡,并提供了具体的方法实现,包括键盘消失时的view还原。

被折叠的 条评论
为什么被折叠?



