如何解决具有动态图像高度的 UICollectionView
我正在尝试使用动态图像高度而不是预先计算的方形图像创建聊天。方形图像与 sizeforItemAt
我正在使用以下代码
// IMPORTANT: this is the key to make your cells auto-sizing
if let collectionViewLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
collectionViewLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
}
override init(frame: CGRect) {
super.init(frame: frame)
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.kf.indicatorType = .activity
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
bubbleView.addSubview(imageView)
imageView.leftAnchor.constraint(equalTo: bubbleView.leftAnchor).isActive = true
imageView.rightAnchor.constraint(equalTo: bubbleView.rightAnchor).isActive = true
// imageView.heightAnchor.constraint(equalTo: self.heightAnchor).isActive = true
imageView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
}
但是,当我使用它时,高度大约是图像的 5 倍......我怎样才能让它正确显示最大宽度为 200 和动态高度的图像?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。