我在UIView
中有一个UITableViewCell
。我正试图用动画改变view
的高度。这是我做的:
self.myViewConstraint.constant = 100; // Coming from 0
[UIView animateWithDuration:0.3f animations:^{
[self.view layoutIfNeeded];
}];
唯一的问题是,它位于tableView
。所以这就是我为heightForRow...
所做的:
return self.myViewConstraint.constant == 0 ? 74 : 174;
现在我需要更新tableView
,因此我插入了animateWithDuration
:
[self.tableView beginUpdates];
[self.tableView endUpdates];
因为我在cell
内有其他内容,所以constraints
在cells
高度动画时搞砸了。如何更新cells
高度而不会让约束搞乱? (我想要cells
高度来制作动画。)
这是我收到的警告。 (一切正常,但我只想删除警告。)
编辑我稍微改了一下,现在我收到了这个错误:
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:0x7f8d62d15670 V:[tagResultTableView:0x7f8d62d901a0(107)]>",
"<NSLayoutConstraint:0x7f8d62cea010 tagResultTableView:0x7f8d62d901a0.top == UITableViewCellContentView:0x7f8d62d8fd50.topMargin - 8>",
"<NSLayoutConstraint:0x7f8d62cf0760 V:[tagResultTableView:0x7f8d62d901a0]-(8)-[UILabel:0x7f8d62d2e2e0'Limit: Up to 5 tags']>",
"<NSLayoutConstraint:0x7f8d62cf0800 UILabel:0x7f8d62d2e2e0'Limit: Up to 5 tags'.bottom == UITableViewCellContentView:0x7f8d62d8fd50.bottomMargin>",
"<NSLayoutConstraint:0x7f8d62f726d0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f8d62d8fd50(32)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f8d62d15670 V:[tagResultTableView:0x7f8d62d901a0(107)]>
答案 0 :(得分:0)
这是一个例子。
Security
答案 1 :(得分:0)
你能做的是
创建自定义UITableViewCell
并为&#39; CustomView&#39;的高度contentView创建一个插座。
@property(弱,非原子)IBOutlet NSLayoutConstraint * heightConstraint;
并设置所有约束。
在viewDidLoad
中设置以下内容
tableView.rowHeight = UITableViewAutomaticDimension;
tableView.estimatedRowHeight = N; // N is some estimated height of your cells
通过更改IBOutlet
方法updateContraints
中的heightConstraint.constant = newHeight
常量来设置高度动画,只要您需要更新UIView
的高度,就可以了可以有
[UIView animateWithDuration:animationDuration animations: ^{
[self.contentView layoutIfNeeded] // This will call to updateContraints you should calculate the new height inside that method
}];
最后致电
[tableView beginUpdates];
[tableView endUpdates];