I feel like this is going to be a simple answer revolving around AutoResizingMasks, but I can't seem to wrap my head around this topic.
I've got an iPad app that shows 2 UITableViews side-by-side. When I rotate from Portrait to Landscape and back, the cells in the UITableView resize perfectly, on-the-fly, while the rotation is occurring. I'm using UITableViewCellStyleSubtitle UITableViewCells (not subclassed for now), and I've set the UITableView up in IB to anchor to the top, left and bottom edges (for the left UITableView) and to have a flexible width.
I'm supplying my own UIView object for
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
Here's what I've got so far (called as a class method from another class):
+ (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;
}
So, in either orientation, everything loads up just like I want. After rotation, if I manually call reloadData or wait until my app triggers it, or scroll the UITableView, the headerViews will resize and show themselves properly. What I can't figure out is how to get the AutoResizeMask property set properly so that the header will resize just like the cells.
I faced the same issue recently. The trick was to use a custom view as the headerView of the table. Overriding layoutSubviews allowed me to control the layout at will. Below is an example.
I have created UIView subclass where I've used visual constraints to stick the subview to the sides of the screen. And rotation is all fine.
I'd love to get a real answer to this, but for now, I've just re-worked my UITableView so that my "headers" are just cells inside the table. Resizing has no issues that way.
Not a very good fix. But works :