动画调整UITableView的UIView标题栏

3
基本上,我想要复制 Facebook iPhone 登录界面的行为:当触摸输入字段时,标志/标题视图会减小高度以腾出键盘的空间。
这里有一个静态内容的 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动画进行完全配置。
1个回答

1
如果您在动画块中添加以下代码,它应该可以修复它:
UIEdgeInsets insets = self.tableView.contentInset;
insets.top -= 50.f;
self.tableView.contentInset = insets;

在这里,self.tableView是指向你的UITableView的插座


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接