質問

I have a summary cell that has it's height calculated using systemLayoutSizeFittingSize. It mostly works as expected. The height is determined by three multi-line labels (title, author, genre) and an ratings image view, with the outer elements tacked to the contentView.

When the title label overflows into the next line, it sizes appropriately. However when the author label overflows, it doesn't seem to increase the size appropriately.

All the compression resistances on the labels and image view are maxed out at 1000. There is an lower priority constraint on the bottom of the thumbnail to the left, in case the content to the right is smaller than the thumbnail. (@750, bottom == 8 from superview bottom). The ratings image view has a constraint to the bottom of the superview as well (@1000, bottom >= 8 from superview bottom).

autolayout issue

役に立ちましたか?

解決

Interesting. So I ended up fixing this by always resetting the reference cell frame height before updating the content and calculating the height. Not entirely sure why this step is needed. I have a couple guesses around the autoresize constraints on the contentView taking precedence:

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case TableSectionSummary: {
            TCAnswerDetailAppSummaryCell *cell = self.summaryCell;
            CGRect oldFrame = self.summaryCell.frame;
            cell.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, mTCTableViewFrameWidth, 400);
            [cell configureWithThirdPartyObject:self.app];
            [cell updateConstraintsIfNeeded];
            [cell layoutIfNeeded];
            CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1;
            return height;
        }
        case TableSectionDetails:
            return [TCAnswerDetailBasicCell heightForCellWithTableWidth:mTCTableViewFrameWidth withLabelString:self.app.appDescription withDisclosureArrow:NO];
    }
    return 0;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top