【发布时间】:2013-05-04 16:04:30
【问题描述】:
基本上,我想复制 iPhone 版 Facebook 登录屏幕中的行为:当触摸输入字段时,徽标/标题视图的高度会降低,以便为键盘腾出空间。
我这里有一个UITableView(带有静态内容):
“控件”实际上是一个 UIView,其中包含 UIImageView 中的徽标,而“表格视图部分”包含用户名/密码的 UITextField。
我的问题是,如何让 UIView(“控件”)降低高度,同时让“表格视图部分”中的 UITableViewCells 自然向上滑动?我尝试了以下方法:
[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 动画完全配置。
【问题讨论】:
标签: iphone ios objective-c uitableview uistoryboard