【发布时间】:2018-09-13 16:07:24
【问题描述】:
我有一个集合视图,它的边缘被限制在安全区域。但是,集合视图完全覆盖了整个屏幕。现在,如果我更改约束删除顶部约束并将其更改为固定高度约束,集合视图仍然会忽略它并填充整个屏幕。当我删除所有约束时,集合视图不会填满整个屏幕。此错误仅影响顶部约束,所有其他约束都可以正常工作。
更新: 当我在 headerView 补充视图委托函数中注释掉一些行时,它再次起作用:
func pressedColour(colour: UIColor){
let origImage = self.imageView?.image
let tintedImage = origImage?.withRenderingMode(.alwaysTemplate)
self.setImage(tintedImage, for: .highlighted)
//self.imageView?.contentMode = .scaleAspectFill
self.tintColor = colour
}
我注释掉的行调用了该函数。自动布局错误是
2018-09-13 23:38:16.556318+0100 DoppelChat[59765:15398941] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x60c00028a780 UICollectionView:0x7fac548e6600.top == UILayoutGuide:0x60c0001bea00'UIViewSafeAreaLayoutGuide'.top (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x60c0004892e0 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' UIView:0x7fac59a7e150.minY == 0 (active, names: '|':_UIParallaxDimmingView:0x7fac59a7eb90 )>",
"<NSLayoutConstraint:0x60c00048b4a0 'UIViewSafeAreaLayoutGuide-top' V:|-(64)-[UILayoutGuide:0x60c0001bea00'UIViewSafeAreaLayoutGuide'] (active, names: '|':UIView:0x7fac59a7e150 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c00028a780 UICollectionView:0x7fac548e6600.top == UILayoutGuide:0x60c0001bea00'UIViewSafeAreaLayoutGuide'.top (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
我已将范围缩小到导致问题的这一行:
let origImage = self.imageView?.image
【问题讨论】:
-
不,只是一个普通的视图控制器
-
也没有什么可以显示的约束,它只是常规对齐到顶部
-
好的,我添加了约束
标签: xcode uicollectionview ios-autolayout