问题描述
我刚刚在 IOS 开发中迈出了第一步,我想将我的 Android 应用程序带到 IOS。
UICollectionView 的问题。我需要单元格具有固定的恒定宽度,并且单元格内的图像具有固定的高度。因此,我将 StackView 的宽度约束设置为 105,将 ImageView 的高度约束设置为 147。
一切都按预期进行,但是我在控制台中收到警告:
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,"<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.
我也尝试将 ImageView 的宽度和高度限制设置为 105x147,它看起来是一样的,警告也几乎一样。基本上,如果没有设置宽度或高度约束 - 没有警告,一旦我添加任何一个 - 它就会出现。
以下是限制条件:
如果您能帮助我了解潜在问题,我将不胜感激。
解决方法
我认为删除堆栈视图的宽度约束会起作用。