ios - 动画时无法同时满足约束

标签 ios cocoa-touch uicollectionview uiviewanimation autolayout

我使用 IB 设置了六个用户约束,如下所示:

H:|-(593)-[UIView(411)]-(20)-|
V:|-(20)-[UIView(288)]-(396)-|

我通过更改约束然后调用 layoutIfNeeded 来扩大和缩小 View 。例如,为了增加 View 我会这样做:

H:|-(20)-[UIView(984)]-(20)-|
V:|-(20)-[UIView(663)]-(20)-|

然后调用

[UIView animateWithDuration:.5 animations:^{
    [self.view layoutIfNeeded];
}];

这种技术可以扩大和缩小我的视野,看起来不错,但我收到了一个相当令人困惑的警告:

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 生成。我已经双重^(三次!)检查了这个。我用笔和纸把这些约束放在一起,得到了这个:

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 生成的约束不是可自动满足的吗?

或者,至少,有没有办法停止警告?它表现完美,我不需要看到它打破了一个似乎什么也没做的约束。

最佳答案

这个约束:

H:[UITableView:0xace7600(319)]>"

似乎是系统解析的障碍。

你能删除它吗?

关于ios - 动画时无法同时满足约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15169158/

相关文章:

objective-c - UICollectionView 删除按钮

swift - 将变量从 Gesture Recognizer 函数传递到 IBAction

ios - 根据 ScrollView 中的位置更改导航栏的标题

ios - Xcode 中的 iPad 序列错误

ios - 尝试从多个实体中获取记录

ios - 如何在 iOS 应用程序中以编程方式创建 PDF 文件?

swift - UICollection View 与 TableView 错误索引超出范围为什么

ios - 异步请求运行缓慢 - iOS

iphone - 在 iPhone 上构建多 View 应用程序

ios - objective-c :检查int是否存在,包括零