我觉得这将是一个围绕 AutoResizingMasks 的简单答案,但我似乎无法理解这个主题。
我有一个 iPad 应用程序,可以并排显示 2 个 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,headerView 将调整大小并正确显示自己。我不知道如何正确设置 AutoResizeMask 属性,以便标题像单元格一样调整大小。
不是一个很好的修复。但有效:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[mTableView reloadData];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)