这两个约束如何冲突?

时间:2015-09-27 05:49:36

标签: ios iphone

我在跟踪一些冲突的约束时遇到了问题。我已经添加了AutoresizingMask,并添加了另一个约束,试图了解正在发生的事情:

2015-09-26 22:27:14.959 Darkenss[26537:8462681] 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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7fc461fe9110 UICollectionView:0x7fc463090000.top == UIView:0x7fc461fc6620.topMargin + 302>",
    "<NSAutoresizingMaskLayoutConstraint:0x7fc461d3f820 h=--- v=--- 'UIView-Encapsulated-Layout-Top' V:[UIView:0x7fc461fc6620]-(0)-|>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fc461fe9110 UICollectionView:0x7fc463090000.top == UIView:0x7fc461fc6620.topMargin + 302>

我不知道这两个约束实际上是如何冲突的。

视图层次结构为:

<UIView: 0x7fc461fc6620; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7fc461fc48a0>>
   | <UIImageView: 0x7fc461fd4f50; frame = (0 0; 600 600); clipsToBounds = YES; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fc7ea0>>
   | <UILabel: 0x7fc461fcba20; frame = (28 68; 300 48); text = 'Darkness AP'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fc461fcb910>>
   | <Darkenss.UIDescreteSliderWithCircles: 0x7fc461e477c0; frame = (28 124; 544 30); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2df00>; layer = <CALayer: 0x7fc461fb09b0>>
   | <UIButton: 0x7fc461e8c8e0; frame = (28 162; 93 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2c770>; layer = <CALayer: 0x7fc461e99bb0>>
   |    | <UIImageView: 0x7fc461d2ad70; frame = (0 6.5; 93 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d2af10>>
   | <UIButton: 0x7fc461e1ee60; frame = (129 162; 92 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2ccd0>; layer = <CALayer: 0x7fc461e1beb0>>
   |    | <UIImageView: 0x7fc461d38d50; frame = (0 6.5; 92 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d38ef0>>
   | <UIButton: 0x7fc461e20c10; frame = (229 162; 93 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2d1f0>; layer = <CALayer: 0x7fc461e372b0>>
   |    | <UIImageView: 0x7fc461d23ab0; frame = (0 6.5; 93 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d23c50>>
   | <UIButton: 0x7fc461e04d20; frame = (330 162; 92 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2d400>; layer = <CALayer: 0x7fc461e225a0>>
   |    | <UIImageView: 0x7fc461d2a9a0; frame = (0 6.5; 92 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d43d80>>
   | <UIButton: 0x7fc461e31e20; frame = (430 162; 81 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461e99d00>; layer = <CALayer: 0x7fc461e31cd0>>
   |    | <UIImageView: 0x7fc461d2c750; frame = (0 6.5; 81 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d1e660>>
   | <UIButton: 0x7fc461e374f0; frame = (16 97.5; 145.5 128); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fc461e34cb0>>
   |    | <UIImageView: 0x7fc461d20da0; frame = (0 0; 145.5 128); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d47ed0>>
   |    | <UIImageView: 0x7fc461e55d50; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461e3d850>>
   |    | <UIButtonLabel: 0x7fc461d20f40; frame = (0 55.5; 27.5 17.5); text = 'Run
 Darkness
Cycle'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fc461d212f0>>
   | <UIButton: 0x7fc461e2d510; frame = (169.5 97.5; 181.5 128); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fc461e60e10>>
   |    | <UIImageView: 0x7fc461d51e50; frame = (0 0; 181.5 128); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d431f0>>
   |    | <UIImageView: 0x7fc461d3c3c0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d3c560>>
   |    | <UIButtonLabel: 0x7fc461d5c0e0; frame = (26.5 55.5; 128.5 17.5); text = ' Continue Combo '; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fc461d52250>>
   | <UIImageView: 0x7fc461fcda20; frame = (4 302; 592 294); clipsToBounds = YES; hidden = YES; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fcd030>>
   | <UICollectionView: 0x7fc463090000; frame = (4 310; 367 353); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461e45640>; layer = <CALayer: 0x7fc461e3b3a0>; contentOffset: {0, 0}; contentSize: {367, 54}> collection view layout: <UICollectionViewFlowLayout: 0x7fc461e468d0>
   |    | <Darkenss.AddTrackerViewCell: 0x7fc4640217f0; baseClass = UICollectionViewCell; frame = (0 0; 54 54); layer = <CALayer: 0x7fc464020fc0>>
   |    |    | <UIButton: 0x7fc4640219c0; frame = (4 4; 46 46); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fc464020e70>>
   |    |    |    | <UIImageView: 0x7fc464024140; frame = (0 0; 46 46); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc4640200b0>>
   |    |    | <UIView: 0x7fc464022110; frame = (0 0; 54 54); autoresize = W+H; gestureRecognizers = <NSArray: 0x7fc4640228f0>; layer = <CALayer: 0x7fc464022270>>
   |    | <Darkenss.CounterArrayCellView: 0x7fc464032270; baseClass = UICollectionViewCell; frame = (54.5 0; 258 53); alpha = 0; layer = <CALayer: 0x7fc464032040>>
   |    |    | <UIView: 0x7fc4640324d0; frame = (0 0; 258 53); gestureRecognizers = <NSArray: 0x7fc464032d10>; layer = <CALayer: 0x7fc464032630>>
   |    |    |    | <Darkenss.CounterArrayView: 0x7fc464032d40; frame = (0 0; 94 102); layer = <CALayer: 0x7fc464034b60>>
   |    |    |    |    | <UILabel: 0x7fc464033190; frame = (6 6; 82 0); text = 'Treasure'; hidden = YES; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fc464033390>>
   |    |    |    |    |    | <_UILabelContentLayer: 0x7fc461d84ee0> (layer)
   |    |    |    |    | <UICollectionView: 0x7fc46388e800; frame = (6 14; 82 82); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7fc4640340a0>; layer = <CALayer: 0x7fc464033ba0>; contentOffset: {0, 0}; contentSize: {82, 81}> collection view layout: <Darkenss.CounterArrayLayout: 0x7fc464033960>
   |    |    |    |    |    | <Darkenss.DotView: 0x7fc461d7e190; baseClass = UICollectionViewCell; frame = (0 0; 40 40); hidden = YES; layer = <CALayer: 0x7fc461d7e530>>
   |    |    |    |    |    |    | <UIView: 0x7fc461d7e550; frame = (0 0; 40 40); gestureRecognizers = <NSArray: 0x7fc461d7ed90>; layer = <CALayer: 0x7fc461d7e6b0>>
   |    |    |    |    |    |    |    | <UIImageView: 0x7fc461d7e370; frame = (0 0; 40 40); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d7e510>>
   |    |    |    |    |    | <Darkenss.DotView: 0x7fc461d82250; baseClass = UICollectionViewCell; frame = (42 0; 40 40); hidden = YES; layer = <CALayer: 0x7fc461d821a0>>
   |    |    |    |    |    |    | <UIView: 0x7fc461d825d0; frame = (0 0; 40 40); gestureRecognizers = <NSArray: 0x7fc461d82e10>; layer = <CALayer: 0x7fc461d82730>>
   |    |    |    |    |    |    |    | <UIImageView: 0x7fc461d82430; frame = (0 0; 40 40); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d821c0>>
   |    |    |    |    |    | <Darkenss.DotView: 0x7fc461d86290; baseClass = UICollectionViewCell; frame = (0 41; 40 40); hidden = YES; layer = <CALayer: 0x7fc461d86610>>
   |    |    |    |    |    |    | <UIView: 0x7fc461d86630; frame = (0 0; 40 40); gestureRecognizers = <NSArray: 0x7fc461d86e80>; layer = <CALayer: 0x7fc461d86790>>
   |    |    |    |    |    |    |    | <UIImageView: 0x7fc461d86470; frame = (0 0; 40 40); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d86240>>
   |    |    |    |    | <UIImageView: 0x7fc464032fd0; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x7fc464033170>>
   |    | <Darkenss.SmallCounterTrackerViewCell: 0x7fc461c90870; baseClass = UICollectionViewCell; frame = (0 53; 108 56); clipsToBounds = YES; alpha = 0; opaque = NO; layer = <CALayer: 0x7fc461c8f970>>
   |    |    | <UIView: 0x7fc461c90a70; frame = (0 0; 188 96); gestureRecognizers = <NSArray: 0x7fc461eb1710>; layer = <CALayer: 0x7fc461c8fb30>>
   |    |    |    | <UIImageView: 0x7fc461c90bd0; frame = (4 4; 88 88); opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461c8fad0>>
   |    |    |    | <Darkenss.OffsetLabels: 0x7fc461c90eb0; frame = (96 4; 88 88); autoresize = RM+BM; layer = <CALayer: 0x7fc461ca0570>>
   |    |    |    |    | <UITextView: 0x7fc462050200; frame = (0 0; 7 14); text = '10'; clipsToBounds = YES; userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x7fc461c92170>; layer = <CALayer: 0x7fc461c91af0>; contentOffset: {0, 0}; contentSize: {7, 55}>
   |    |    |    |    |    | <<_UITextContainerView: 0x7fc461c92c00; frame = (0 0; 7 55); layer = <_UITextTiledLayer: 0x7fc461c92dd0>> minSize = {0, 0}, maxSize = {1.7976931348623157e+308, 1.7976931348623157e+308}, textContainer = <NSTextContainer: 0x7fc461c918f0 size = (7.000000,340282346638528859811704183484516925440.000000); widthTracksTextView = YES; heightTracksTextView = NO>; exclusionPaths = 0x7fc461c00dc0; lineBreakMode = 0>
   |    |    |    |    |    |    | <UITextSelectionView: 0x7fc461c95070; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461c94fb0>>
   |    |    |    |    | <UITextView: 0x7fc462052000; frame = (0 0; 9 14); text = '10'; clipsToBounds = YES; userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x7fc461c99480>; layer = <CALayer: 0x7fc461c98df0>; contentOffset: {0, 0}; contentSize: {9, 55}>
   |    |    |    |    |    | <<_UITextContainerView: 0x7fc461c9a270; frame = (0 0; 9 55); layer = <_UITextTiledLayer: 0x7fc461c9a440>> minSize = {0, 0}, maxSize = {1.7976931348623157e+308, 1.7976931348623157e+308}, textContainer = <NSTextContainer: 0x7fc461c98bd0 size = (9.000000,340282346638528859811704183484516925440.000000); widthTracksTextView = YES; heightTracksTextView = NO>; exclusionPaths = 0x7fc461c00dc0; lineBreakMode = 0>
   |    |    |    |    |    |    | <UITextSelectionView: 0x7fc461c9c750; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461c9c690>>
   |    |    |    |    | <CAShapeLayer: 0x7fc461d7d7a0> (layer)
   |    | <UIImageView: 0x7fc461e44520; frame = (361.5 284; 2.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461e3f7f0>>
   | <UIImageView: 0x7fc461fd19f0; frame = (3 292; 286 21); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fd00c0>>
   | <UIImageView: 0x7fc461fdbec0; frame = (289 292; 23 21); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fdb6e0>>
   | <UIImageView: 0x7fc461fe1540; frame = (312 292; 285 21); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fd1b90>>
   | <_UILayoutGuide: 0x7fc461fe6260; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7fc461fe5f50>>
   | <_UILayoutGuide: 0x7fc461fe6cb0; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7fc461fe5aa0>>

更新:我丢失了项目所依赖的硬盘(但我的备份只有45分钟,所以当我得到替代品时它会全部解决... “我至少有希望)。但是我有一个很大的线索。

我在KVO观察者中计算约束和触发布局。这个观察者在视图有超视图之前触发了。跳过视图具有超级视图之前发生的更新可避免此问题。再考虑一点,并且:

  

'UIView-Encapsulated-Layout-Top'V:[UIView:0x7fc461fc6620] - (0) - |

让我觉得 - (0) - 是“哦,视图是零高度,感谢玩”,因为所说的视图没有超视图,自动布局只是不想处理那个烂摊子。

希望我能在10月初恢复正常运行的硬件并找出它是什么!

1 个答案:

答案 0 :(得分:0)

也许您忘记为您使用约束以编程方式添加的某些视图设置translatesAutoresizingMaskIntoConstraints = NO。这可能解释了AutoresizingMask。请检查。

<强>更新: 此外,对于此约束:

<NSLayoutConstraint:0x7fc461fe9110 UICollectionView:0x7fc463090000.top == UIView:0x7fc461fc6620.topMargin + 302>

尝试将UIView:0x7fc461fc6620.topMargin更改为UIView:0x7fc461fc6620.top

我猜你在计算常数“302”

时没有计算余量