File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,11 +96,22 @@ - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier configuration:(
9696 } else {
9797 // Add a hard width constraint to make dynamic content views (like labels) expand vertically instead
9898 // of growing horizontally, in a flow-layout manner.
99- NSLayoutConstraint *tempWidthConstraint = [NSLayoutConstraint constraintWithItem: cell.contentView attribute: NSLayoutAttributeWidth relatedBy: NSLayoutRelationEqual toItem: nil attribute: NSLayoutAttributeNotAnAttribute multiplier: 1.0 constant: contentViewWidth];
100- [cell.contentView addConstraint: tempWidthConstraint];
101- // Auto layout engine does its math
102- fittingSize = [cell.contentView systemLayoutSizeFittingSize: UILayoutFittingCompressedSize];
103- [cell.contentView removeConstraint: tempWidthConstraint];
99+
100+ /* 修复1.3版本存在的一个bug:给contentView添加宽度为0的约束,会与已有子视图约束冲突. */
101+ if (0 != contentViewWidth) {
102+ NSLayoutConstraint *tempWidthConstraint =
103+ [NSLayoutConstraint constraintWithItem: cell.contentView
104+ attribute: NSLayoutAttributeWidth
105+ relatedBy: NSLayoutRelationEqual
106+ toItem: nil
107+ attribute: NSLayoutAttributeNotAnAttribute
108+ multiplier: 1.0
109+ constant: contentViewWidth];
110+ [cell.contentView addConstraint: tempWidthConstraint];
111+ // Auto layout engine does its math
112+ fittingSize = [cell.contentView systemLayoutSizeFittingSize: UILayoutFittingCompressedSize];
113+ [cell.contentView removeConstraint: tempWidthConstraint];
114+ }
104115 }
105116
106117 // Add 1px extra space for separator line if needed, simulating default UITableViewCell.
You can’t perform that action at this time.
0 commit comments