【问题标题】:Change Auto Constraint height of UIView更改 UIView 的自动约束高度
【发布时间】:2015-01-26 23:41:25
【问题描述】:

我在 UITableViewCell 中有一个 UIView。在视图中,我有一个 UITextView 和一个 UIView。它们在所有 4 个方面都是自动约束。

UIView 有高度限制。我想以编程方式更新高度约束。我做了一个高度限制的出口,所以我可以改变它。

这是我的代码:

CGRect frame = self.myView.frame;
frame.size.height = 50;
frame.size.width = self.myView.frame.size.width;
self.myView.frame = frame;
self.viewHeight.constant = 50;

[myTableView reloadData];

当我运行这段代码时,它运行良好,但我收到一个错误:(我对目标 c 很陌生,所以我不明白它想说什么。)

2015-01-26 15:25:43.408 myApp[1449:55334] 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:0x7fb07853ac20 V:[UIView:0x7fb0784dbb80(50)]>",

    "<NSLayoutConstraint:0x7fb0785bd170 V:|-(0)-[UITextView:0x7fb07896de00]   (Names: '|':UIView:0x7fb07857fb70 )>",

    "<NSLayoutConstraint:0x7fb0785bd260 V:[UITextView:0x7fb07896de00]-(3)-[UIView:0x7fb0784dbb80]>",

    "<NSLayoutConstraint:0x7fb0785bd350 V:[UIView:0x7fb0784dbb80]-(0)-|   (Names: '|':UIView:0x7fb07857fb70 )>",

    "<NSLayoutConstraint:0x7fb0785bd5b0 UILabel:0x7fb0785150f0'info:'.top == UITableViewCellContentView:0x7fb078581400.topMargin>",

    "<NSLayoutConstraint:0x7fb0785bd650 UITableViewCellContentView:0x7fb078581400.bottomMargin == UIView:0x7fb07857fb70.bottom + 1>",

    "<NSLayoutConstraint:0x7fb0785bd6f0 V:[UILabel:0x7fb0785150f0'info:']-(8)-[UIView:0x7fb07857fb70]>",

    "<NSLayoutConstraint:0x7fb078704f20 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fb078581400(77)]>"

)



Will attempt to recover by breaking constraint 

<NSLayoutConstraint:0x7fb07853ac20 V:[UIView:0x7fb0784dbb80(50)]>



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.

【问题讨论】:

  • “无法同时满足约束条件。”这意味着自动布局系统无法满足您的约束,因为约束包含冲突。尝试检查您的约束代码
  • 所有其他约束都在情节提要中进行,并且没有错误

标签: ios objective-c uitableview uiview nslayoutconstraint


【解决方案1】:

您以编程方式将高度约束更改为 50。它对 iOS 为 UITableViewCellContentView 设置的 UIView-Encapsulated-Layout-Height 约束 (77) 不满意。

【讨论】:

  • 在 heightForRowAtIndexPth 我的返回语句如下:return txtView.frame.size.height + self.myView.frame.size.height + 44 - 0.5;
  • @MikeRally txtView.frame.size.height + self.myView.frame.size.height + 44 - 0.5 是否应该是 50 ?无论如何,我不建议混合故事板约束和编程设置约束。它往往会导致许多意想不到的问题。
  • 没有。 self.myView.frame.size.height 是 50。我通常不这样做,但我必须在情节提要中为 myView 分配一个高度,并且我正在尝试以编程方式更改高度。
  • @MikeRally 要删除警告,您可以尝试在分配新约束之前删除先前的约束。这个答案stackoverflow.com/a/27621707/3562486 可能会有所帮助。
猜你喜欢
  • 1970-01-01
  • 2019-10-12
  • 2015-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多