Change UITableViewCell Height on Orientation Change

前端 未结 2 1787
一整个雨季
一整个雨季 2021-02-08 03:25

I have a UITableView with cells containing variable-height UILabels. I am able to calculate the minimum height the label needs to be using sizeWithFont:constrainedToSize:l

2条回答
  •  再見小時候
    2021-02-08 04:06

    To improve slightly on the answer above from @David and to answer the last comment about how to animate it smoothly during a rotation, use this method:

    - (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
        [self.tableView beginUpdates];
        [self.tableView endUpdates];
    }
    

    and of course the height delegate method:

    - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
            return 171.0f;
        } else {
            return 128.0f;
        }
    }
    

提交回复
热议问题