集合视图不遵循Xcode中的约束

时间:2018-09-13 16:07:25

标签: xcode uicollectionview ios-autolayout

我有一个集合视图,其边缘限制在安全区域内。但是,集合视图完全覆盖了整个屏幕。现在,如果我更改约束,请移除顶部约束并将其更改为固定的高度约束,集合视图仍会忽略它并填充整个屏幕。当我删除所有约束时,集合视图不会填满整个屏幕。此错误仅影响顶部约束,所有其他约束都可以正常工作。

更新: 当我在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

1 个答案:

答案 0 :(得分:0)

好的,我已经解决了,如果对您来说有什么用,我改用此功能作为按钮的颜色:

mainline

我传入的uiImage参数是图片文字,而不是button.imageview.image