0

Just making my first steps in IOS development, and I want to bring my Android app to IOS.

The issue it with UICollectionView. I need the cells to be of fixed constant width, and the image inside the cell - of fixed height. So, I've set the width constraint of StackView to 105 and height constraint for ImageView to 147.

Everything looks as expected, however I get warnings in the console:

2021-02-21 22:23:17.490472+0200 myapp-ios[20727:783655] [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:0x600002193890 UIStackView:0x7f90efc173d0.width == 105   (active)>",
    "<NSLayoutConstraint:0x6000021938e0 H:[UIStackView:0x7f90efc173d0]-(0)-|   (active, names: '|':UIView:0x7f90efc1d840 )>",
    "<NSLayoutConstraint:0x600002193930 H:|-(0)-[UIStackView:0x7f90efc173d0]   (active, names: '|':UIView:0x7f90efc1d840 )>",
    "<NSLayoutConstraint:0x600002193a20 'UIIBSystemGenerated' myapp_ios.ShowCell:0x7f90efc23ec0.leading == UIView:0x7f90efc1d840.leading   (active)>",
    "<NSLayoutConstraint:0x600002193a70 'UIIBSystemGenerated' H:[UIView:0x7f90efc1d840]-(0)-|   (active, names: '|':myapp_ios.ShowCell:0x7f90efc23ec0 )>",
    "<NSLayoutConstraint:0x6000021967b0 'UIView-Encapsulated-Layout-Width' myapp_ios.ShowCell:0x7f90efc23ec0.width == 50   (active)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600002193890 UIStackView:0x7f90efc173d0.width == 105   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.

I also tried to set width and height constraints of ImageView only to 105x147, it looks the same, and the warning is pretty much the same. Basically if no width or height constraints set - there is no warning, once I add any of them - it appears.

Here are the constraints:

enter image description here

I would appreciate you helping me understand the potential problem.

ievgen
  • 1,010
  • 11
  • 17
  • Use http://wtfautolayout.com. You don't want the stack view width constraint if you are constraining leading and trailing edges. The width will be inferred. To fix the size of the cells, use the collection view flow layout delegate function. – Paulw11 Feb 21 '21 at 21:30
  • The delegate function return CGSize where all the fields must be > 0. So the desired width I know, but height - no, I know only the desired height of the image view but not of the whole cell. – ievgen Feb 22 '21 at 07:59
  • You need your cells to auto size https://stackoverflow.com/questions/25895311/uicollectionview-self-sizing-cells-with-auto-layout – Paulw11 Feb 22 '21 at 09:49

1 Answers1

0

I think removing the width constraint of the stack view will work.