基本上,我想要复制 Facebook iPhone 登录界面的行为:当触摸输入字段时,标志/标题视图会减小高度以腾出键盘的空间。
这里有一个静态内容的 UITableView:
"Control" 实际上是一个包含标志的 UIView,其中标志位于 UIImageView 中,“Table View Section” 包含用于用户名/密码的 UITextFields。
我的问题是,如何动画地使 UIView(“Control”)减小高度,同时让“Table View Section”中的 UITableViewCell 自然滑动?我尝试了以下操作:
它的表现非常出色,可以通过UIView动画进行完全配置。
这里有一个静态内容的 UITableView:
"Control" 实际上是一个包含标志的 UIView,其中标志位于 UIImageView 中,“Table View Section” 包含用于用户名/密码的 UITextFields。
我的问题是,如何动画地使 UIView(“Control”)减小高度,同时让“Table View Section”中的 UITableViewCell 自然滑动?我尝试了以下操作:
[UIView animateWithDuration:1.0f animations:^{
CGRect theFrame = _headerView.frame;
theFrame.size.height -= 50.f;
_headerView.frame = theFrame;
}];
_headerView
是头部的UIView
。它被调整大小,但是UITableView
没有像调整UITableViewCell
一样有反应(即登录UITableViewCells
不会上移)。我该如何解决?
我看到过如何调整UITableViewCell
大小的示例,但我不能将标头/徽标放在UITableViewCell
中,因为表视图部分是分组的,不应该看起来像登录部分。
编辑
很好的答案!这里是我最终的动画效果,使用了一个view_is_up
实例变量:
-(void)moveTableView:(BOOL)up{
float move_distance = 55.f;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.3f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
UIEdgeInsets insets = self.tableView.contentInset;
if(view_is_up&&!up){
insets.top += move_distance;
view_is_up = NO;
}
else if(!view_is_up&&up){
insets.top -= move_distance;
view_is_up = YES;
}
self.tableView.contentInset = insets;
[UIView commitAnimations];
}
它的表现非常出色,可以通过UIView动画进行完全配置。