动画无法在同时满足约束条件 [英] Unable to simultaneously satisfy constraints when animating
问题描述
我有IB六个用户限制设置看起来像这样的:
I have six user constraints setup with IB that look like this:
H:|-(593)-[UIView(411)]-(20)-|
V:|-(20)-[UIView(288)]-(396)-|
我长大和收缩,通过改变约束条件,然后调用layoutIfNeeded的看法。例如,成长的看法,我会做的事:
I grow and shrink the view by changing the constraints and then calling layoutIfNeeded. For example, to grow the view I will do:
H:|-(20)-[UIView(984)]-(20)-|
V:|-(20)-[UIView(663)]-(20)-|
然后调用
[UIView animateWithDuration:.5 animations:^{
[self.view layoutIfNeeded];
}];
此技术的发展和缩小我的观点,它看起来不错,但我给予了相当混乱的警告:
This technique grows and shrinks my view, and it looks nice, but I'm given a rather confusing warning:
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:0x148d5af0 H:[UIView:0x148d4e50(411)]>",
"<NSLayoutConstraint:0x148cc940 H:[UITableView:0xace7600(319)]>",
"<NSLayoutConstraint:0x148ce040 H:|-(NSSpace(20))-[UITableView:0xacd4e00] (Names: '|':UIView:0x148cddd0 )>",
"<NSLayoutConstraint:0x148cdf00 H:[UITableView:0xace7600]-(NSSpace(20))-| (Names: '|':UIView:0x148cddd0 )>",
"<NSLayoutConstraint:0x148cdea0 H:[UITableView:0xacd4e00]-(NSSpace(8))-[UITableView:0xace7600]>",
"<NSLayoutConstraint:0x148d4c10 UIView:0x148cddd0.trailing == UIView:0x148cdd40.trailing>",
"<NSLayoutConstraint:0x148d4b90 H:|-(0)-[UIView:0x148cddd0] (Names: '|':UIView:0x148cdd40 )>",
"<NSLayoutConstraint:0x148d6020 H:|-(320)-[UIView:0x148cdd40] (Names: '|':UIView:0x148cd330 )>",
"<NSLayoutConstraint:0x148d5fa0 UIView:0x148cdd40.trailing == UIView:0x148cd330.trailing>",
"<NSLayoutConstraint:0x148d5f60 H:[UIView:0x148d4e50]-(NSSpace(20))-| (Names: '|':UIView:0x148cd330 )>",
"<NSLayoutConstraint:0x148d5ee0 H:|-(20)-[UIView:0x148d4e50] (Names: '|':UIView:0x148cd330 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x148cc940 H:[UITableView:0xace7600(319)]>
现在所有这些约束是由IB产生。我有双^(三倍!)选中此。我已经把这些限制连同笔和纸,并已经得到了这一点:
Now all of these constraints are generated by IB. I've double^(triple!) checked this. I've put these constraints together with a pen and paper and have gotten this:
UIView_A H:[-(20)-[UIView_E]-(20)-] and H:[-(320)-(UIView_B)
UIView_B H:[-(0)-[UIView_D]
UIView_C H:[UIView_C(411)]
UIView_D H:[-(20)-[UITableView_F]-[UITableView_G(319)]-(20)-]
我不明白这些限制怎么也无法得到满足。他们看起来很好。我不改变他们,他们正在通过IB生成的。不是由IB产生约束自动满足的?
I don't understand how these constraints can't be satisfied. They look fine. I don't change them and they're generated by IB. Aren't constraints generated by IB automatically satisfiable?
或者,至少,有没有办法阻止警告?它完美的表现,我也不需要看到的是它打破似乎并不反正做任何事情的约束。
Or, at a minimum, is there a way to stop warnings? It behaves perfectly and I don't need to see that it's breaking a constraint that doesn't seem to do anything anyway.
推荐答案
所以,事实证明,在这我改变制约事项的顺序。
So, it turns out, the order at which I change constraints matters.
要增长的观点,我会
- 增加宽度:H:| - (593) - [UIView的( 984 )] - (20) - |
- 降低前导空格:H:| - ( 20 ) - [UIView的(984) - (20) - |
- Increase the width: H:|-(593)-[UIView(984)]-(20)-|
- Decrease the leading space: H:|-(20)-[UIView(984)]-(20)-|
这不会产生任何警告。但是,如果我这样做了相反的顺序,我会得到一个警告:
This produces no warnings. However, if I do this in the opposite order, I'll get a warning:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints ...
...Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1567f650 H:[UITableView:0x119e6200(319)]>
在萎缩的观点,我复制了code,它增加了宽度(具有相同的顺序),只是改变了值。这给了我我张贴在我原来的问题的警告。当我切换顺序萎缩,消失的警告。
When shrinking the view, I copied the code that increased the width (with the same order) and just changed the values. That gave me the warning I posted in my original question. When I switched the order for shrinking, the warnings disappeared.
为什么会出现这种情况?我不知道。我发现更多的我会及时更新。
Why is this the case? I don't know. I'll update as I discover more.
这篇关于动画无法在同时满足约束条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!