更改 UIView 的自动约束高度

Change Auto Constraint height of UIView

我在 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];

当我 运行 这段代码时,它运行完美,但我收到一个错误:(我是 objective 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.

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