0





122

Advertisement

I have a tableview with a tableview header (not section header) that both resize depending on the orientation. In my implementation I'm setting the frames for both views in viewWillLayoutSubviews.

My problem right now is that while both are resizing properly individually after rotating, the tableView's origin isn't changing to take into account of the header's height change. This is leading to a space appearing between them or the header covering some of the cells.

My goal is to have in portrait, the tableview be of screen width with a long header. When rotated to landscape the width diminishes to a third of the screen width, right justified, with a shorter header. As well, I need the rotation animation for all of these changes to be smooth and logical.

I'm fairly green to iOS rotation and animation practises so if anyone has better suggestions I'd definitely appreciate them.

Question author K-he | Source

Advertisement


0


Table view won't respect new header height until you reassign tableHeader.

Similar questions:

When rotation will or did finish you could do the following:

- (void)didRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    self.tableView.tableHeaderView = self.tableView.tableHeaderView;
}

In fact, here's also the place where you could calculate header's height:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    CGRect frame = self.tableView.tableHeaderView.frame;
    frame.size.height = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 50 : 150;
    self.tableView.tableHeaderView.frame = frame;

    self.tableView.tableHeaderView = self.tableView.tableHeaderView;
}
Answer author Vokilam