Auto Layout calculating wrong height when height depends on width of inner view
| Originator: | michaelhochs | ||
| Number: | rdar://24040051 | Date Originated: | 2015-01-04 |
| Status: | Open | Resolved: | |
| Product: | iOS | Product Version: | 9.2 |
| Classification: | Bug | Reproducible: | Always |
Summary: When calculating the height of a view with `systemLayoutSizeFittingSize:` the height calculation is wrong if the height of the view depends on the result of auto layout width of a child view of the receiver. Steps to Reproduce: - See the attached sample project. - Run it on an iPhone 5 / 5s. (the screen size is the important factor here) Expected Results: - The cell has the correct height, so that the left label isn’t rendering out of the cell’s bounds. Actual Results: - The cell is too small so that the label with the text does render outside of the cell’s bounds. Regression: — Notes: The issue does not occur as soon as you give the button (right view) the final text already in the xib file. The issue only occurs when the right view needs to change its width because of a text change.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Engineering has the following feedback for you:
Please either use self-sizing table view cells or correct the sample app as follows:
In ViewController.m -tableView:heightForCellAtIndexPath: should look like this:
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath )indexPath { HRSReservationConfirmationMyHRSTeaserCell dummyCell = [[[UINib nibWithNibName:@"HRSReservationConfirmationMyHRSTeaserCell" bundle:nil] instantiateWithOwner:nil options:nil] firstObject]; CGSize size = [dummyCell.contentView systemLayoutSizeFittingSize:CGSizeMake(CGRectGetWidth(tableView.bounds), 0) withHorizontalFittingPriority:UILayoutPriorityRequired verticalFittingPriority:UILayoutPriorityFittingSizeLevel]; return size.height + 1.0/[[UIScreen mainScreen] scale]; }
Remove the -layoutSubviews override in HRSReservationConfirmationMyHRSTeaserCell
Thank you for your feedback. Engineering has determined that this issue behaves as intended.
We are now closing this bug report.
If you just have questions about the resolution, then please update your bug report with that information so we can respond.