【发布时间】:2019-01-16 10:51:14
【问题描述】:
视频:
您可以在视频中看到我遇到的问题。图像高度约束被破坏,导致标签也缺少高度。它们位于 tableview 部分(UITableHeaderFooter 类)。我用automaticDimension计算了它的高度并修正了结果。
这是图像视图约束。 (默认高度约束为 184 并且在运行时更新取决于比率。)
https://uphinhnhanh.com/image/SAezyz
以及标签约束:
https://uphinhnhanh.com/image/SAeT5Y
问题发生在我致电table reload 重新配置剖面视图数据和高度然后下载图像之后。我收到了损坏的约束警告。 Xcode 打破了导致问题的 imageview 高度约束。
(
"<NSLayoutConstraint:0x2807252c0 UIImageView:0x109c002d0.height == 735.885 (active)>",
"<NSLayoutConstraint:0x280727160 UIImageView:0x109c007f0.height == 40 (active)>",
"<NSLayoutConstraint:0x280715900 UIView:0x109c00d10.height == 51 (active)>",
"<NSLayoutConstraint:0x2807140f0 UILayoutGuide:0x281d7e680'UIViewSafeAreaLayoutGuide'.bottom == UIView:0x109c00d10.bottom (active)>",
"<NSLayoutConstraint:0x2807174d0 V:|-(11)-[UIImageView:0x109c007f0] (active, names: '|':engie_up.PostDetailHeaderView:0x109c00000 )>",
"<NSLayoutConstraint:0x280717c50 V:[UIImageView:0x109c007f0]-(18.5)-[engie_up.KwExpandableContextLabel:0x10491c600'bfbfnff'] (active)>",
"<NSLayoutConstraint:0x280715130 V:[engie_up.KwExpandableContextLabel:0x10491c600'bfbfnff']-(18)-[UIImageView:0x109c002d0] (active)>",
"<NSLayoutConstraint:0x280714fa0 V:[UIImageView:0x109c002d0]-(0)-[UIView:0x109c00d10] (active)>",
"<NSLayoutConstraint:0x28072ad00 'UIView-Encapsulated-Layout-Height' engie_up.PostDetailHeaderView:0x109c00000.height == 343 (active)>",
"<NSLayoutConstraint:0x2807179d0 'UIViewSafeAreaLayoutGuide-bottom' V:[UILayoutGuide:0x281d7e680'UIViewSafeAreaLayoutGuide']-(0)-| (active, names: '|':engie_up.PostDetailHeaderView:0x109c00000 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x2807252c0 UIImageView:0x109c002d0.height == 735.885 (active)>
我注意到'UIView-Encapsulated-Layout-Height' 是估计高度。
获取代码很简单,因为我使用的是翠鸟
let ratio = CGFloat(image.width) / CGFloat(image.height)
userContentImageViewHeightConstraint.constant = CGFloat((UIScreen.main.bounds.width) / ratio)
self.userContentImageView.kf.indicatorType = .activity
self.userContentImageView.kf.setImage(with: URL(string: image.url), completionHandler: { (_, _, _, _) in
self.setNeedsLayout()
self.layoutIfNeeded()
})
所以我想问一下如何正确修复约束中断?
谢谢。
【问题讨论】:
-
您的视图的视觉外观是什么?您可以添加您制作的内容和您想要制作的内容的屏幕截图吗?
-
@SyedQamarAbbas,我已经上传了视频。当我向下滚动并且图像被收缩和拉伸时,您可以看到标签丢失。
标签: ios uitableview autolayout kingfisher