设置了estimatedRowHeight后,用masonry 计算出来的cell高度没问题,但是contentsize确有问题,
ContentSize是estimatedRowHeight的值 乘以cell的个数,有大神遇到吗?
estimatedRowHeight masonry
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
你知我知皆知 2024-08-05 23:50关注以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
这个问题是因为在iOS中,masonry计算cell的高度时,它会考虑到content size和estimated row height。如果内容大小大于estimated row height,则cell的高度会被调整为内容大小;否则,cell的高度仍保持为estimated row height。
例如:
let estimatedRowHeight = 50.0 // 设置的estimatedRowHeight let contentSize = CGSize(width: 100, height: 200) // 设置的内容大小 if contentSize.height > estimatedRowHeight { cell.frame.size.height = contentSize.height } else { cell.frame.size.height = estimatedRowHeight }如果你发现内容大小大于estimated row height,但cell的高度还是按照estimated row height来设置的,那么你需要检查你的masonry布局是否正确。你可以在layoutSubviews方法中添加以下代码:
func layoutSubviews() { super.layoutSubviews() if contentSize.height > estimatedRowHeight { cell.frame.size.height = contentSize.height } else { cell.frame.size.height = estimatedRowHeight } }这样,即使内容大小大于estimated row height,cell的高度也会根据内容大小进行调整。
解决 无用评论 打赏 举报