无法同时满足约束,将尝试通过打破约束来恢复 [英] Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint

查看:26
本文介绍了无法同时满足约束,将尝试通过打破约束来恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我在调试区收到的错误信息.它运行良好,除了我收到此错误外,没有任何问题.这会阻止苹果接受该应用程序吗?我该如何解决?

Below is the error message I receive in the debug area. It runs fine and nothing is wrong except that I receive this error. Would this prevent apple accepting the app? How do I fix it?

2012-07-26 01:58:18.621 Rolo[33597:11303] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x887d630 h=--& v=--& V:[UIButtonLabel:0x886ed80(19)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x887d5f0 h=--& v=--& UIButtonLabel:0x886ed80.midY == + 37.5>",
    "<NSAutoresizingMaskLayoutConstraint:0x887b4b0 h=--& v=--& V:[UIButtonLabel:0x72bb9b0(19)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x887b470 h=--& v=--& UIButtonLabel:0x72bb9b0.midY == - 0.5>",
    "<NSLayoutConstraint:0x72bf860 V:[UILabel:0x72bf7c0(17)]>",
    "<NSLayoutConstraint:0x72c2430 UILabel:0x72bfad0.top == UILabel:0x72bf7c0.top>",
    "<NSLayoutConstraint:0x72c2370 UILabel:0x72c0270.top == UILabel:0x72bfad0.top>",
    "<NSLayoutConstraint:0x72c22b0 V:[UILabel:0x72bf7c0]-(NSSpace(8))-[UIButton:0x886efe0]>",
    "<NSLayoutConstraint:0x72c15b0 V:[UILabel:0x72c0270]-(NSSpace(8))-[UIRoundedRectButton:0x72bbc10]>",
    "<NSLayoutConstraint:0x72c1570 UIRoundedRectButton:0x72bbc10.baseline == UIRoundedRectButton:0x7571170.baseline>",
    "<NSLayoutConstraint:0x72c21f0 UIRoundedRectButton:0x7571170.top == UIButton:0x886efe0.top>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x72bf860 V:[UILabel:0x72bf7c0(17)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

推荐答案

我建议调试并找出哪个约束是你不想要的".假设您有以下问题:

I would recommend to debug and find which constraint is "the one you don't want". Suppose you have following issue:

问题始终是如何找到以下约束和视图.

有两种解决方法:

  1. DEBUG VIEW HIERARCHY (不推荐这种方式)

因为您知道在哪里可以找到意外的约束 (PBOUserWorkDayHeaderView),所以有一种方法可以很好地做到这一点.让我们在红色矩形中找到 UIViewNSLayoutConstraint .由于我们知道他们在内存中的id,这很容易.

Since you know where to find unexpected constraints (PBOUserWorkDayHeaderView) there is a way to do this fairly well. Lets find UIView and NSLayoutConstraint in red rectangles. Since we know their id in memory it is quite easy.

  • 使用调试视图层次结构停止应用:

  • 找到合适的 UIView:

  • 接下来是找到我们关心的NSLayoutConstraint:

如您所见,内存指针是相同的.所以我们知道现在发生了什么.此外,您可以在视图层次结构中找到 NSLayoutConstraint.因为它是在视图中被选中的,所以它也在导航器中被选中.

As you can see, the memory pointers are the same. So we know what is going on now. Additionally you can find NSLayoutConstraint in view hierarchy. Since it is selected in View, it selected in Navigator also.

如果您需要,您也可以使用地址指针在控制台上打印:

If you need you may also print it on console using address pointer:

(lldb) po 0x17dce920
<UIView: 0x17dce920; frame = (10 30; 300 24.5); autoresize = RM+BM; layer = <CALayer: 0x17dce9b0>>

您可以对调试器指向您的每个约束执行相同的操作:-) 现在您决定如何处理它.

You can do the same for every constraint the debugger will point to you:-) Now you decide what to do with this.

  1. 打印效果更好 (我真的推荐这种方式,这是 Xcode 7 的)

  • 为视图中的每个约束设置唯一标识符:

  • NSLayoutConstraint 创建简单的扩展:
  • create simple extension for NSLayoutConstraint:

SWIFT:

extension NSLayoutConstraint {

    override public var description: String {
        let id = identifier ?? ""
        return "id: (id), constant: (constant)" //you may print whatever you want here
    }
}

目标-C

@interface NSLayoutConstraint (Description)

@end

@implementation NSLayoutConstraint (Description)

-(NSString *)description {
    return [NSString stringWithFormat:@"id: %@, constant: %f", self.identifier, self.constant];
}

@end

  • 再次构建它,现在您有更多可读的输出:
    • 获得id 后,您可以在查找导航器中简单地点击它:
    • once you got your id you can simple tap it in your Find Navigator:

    • 并快速找到它:

    如何简单地解决这个问题?

    • 尝试将 priority 更改为 999 以解除约束.
    • try to change priority to 999 for broken constraint.

    这篇关于无法同时满足约束,将尝试通过打破约束来恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆