removeConstraint 无效

发布于 2022-09-03 15:22:22 字数 1919 浏览 9 评论 0

相关代码:

[self.scrollView removeConstraint:self.introduceTitleLabelTopConstraint];
NSLayoutConstraint* constraint = [NSLayoutConstraint constraintWithItem:self.introduceTitleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeTop multiplier:1 constant:0];
[self.scrollView addConstraint:constraint];

相关日志:
其中倒数第二行是我新增的约束,最后一行是我删除的约束,这个日志为什么还要打印我已经删掉的约束?

2016-09-18 12:03:15.206 GamePlatform[48552:616181] 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. 
(
    "<NSLayoutConstraint:0x7f8612190d90 UIImageView:0x7f86126062c0.top == UIView:self.noticeContainer.top>",
    "<NSLayoutConstraint:0x7f86121c60b0 UIView:self.noticeBackgroundView.top == UIImageView:0x7f86126062c0.top + 15>",
    "<NSLayoutConstraint:0x7f86121c6100 UIView:self.noticeContainer.bottom == UIView:self.noticeBackgroundView.bottom>",
    "<NSLayoutConstraint:0x7f861260b0a0 UIView:self.noticeContainer.top == UIScrollView:self.scrollView.top>",
    "<NSLayoutConstraint:0x7f86105e2550 ZLIconLabel:self.introduceTitleLabel.top == UIScrollView:self.scrollView.top>",
    "<NSLayoutConstraint:0x7f86121c0550 ZLIconLabel:self.introduceTitleLabel.top == UIView:self.noticeContainer.bottom>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f86121c60b0 UIView:self.noticeBackgroundView.top == UIImageView:0x7f86126062c0.top + 15>

还有个问题就是,虽然界面上显示是正确的,为什么会出现 'Unable to simultaneously satisfy constraints.' 错误?

而且提示的 breaking constraint 跟我要修改的约束没有任何关联。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慢慢从新开始 2022-09-10 15:22:24

backButton.translatesAutoresizingMaskIntoConstraints = false
constLabelTop.active = false
NSLayoutConstraint(item: label, attribute: .CenterY, relatedBy: .Equal, toItem: backButton, attribute: .CenterY,multiplier: 1, constant: 0).active = true
self.view.layoutIfNeeded()
https://stackoverflow.com/que...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文