我觉得这将是一个简单的答案,涉及到AutoResizingMasks,但我似乎无法理解这个主题。
我有一个iPad应用程序,显示两个并排的UITableView。当我从纵向旋转到横向,然后再旋转回来时,UITableView中的单元格会在旋转发生时实时地完美调整大小。我正在使用UITableViewCellStyleSubtitle UITableViewCells(暂时没有子类化),并且我已经在IB中设置了UITableView以锚定顶部、左侧和底部边缘(对于左侧的UITableView),并具有可伸缩宽度。
我为自己提供了一个UIView对象
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
这是我目前的代码(从另一个类中调用的类方法):
+ (UIView *)headerForTableView:(UITableView *)tv
{
// The view to return
UIView *headerView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, [tv frame].size.width, someHeight)];
[headerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin];
// Other layout logic... doesn't seem to be the culprit
// Return the HeaderView
return headerView;
}
因此,在任何方向上,一切都可以按照我的要求加载。在旋转后,如果我手动调用reloadData或等待我的应用程序触发它,或者滚动UITableView,headerViews将重新调整大小并显示正确。我无法弄清楚的是如何正确设置AutoResizeMask属性,以便头部可以像单元格一样调整大小。