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

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

问题描述

以下是我在调试区域收到的错误信息。它运行正常,没有什么是错的,除了我收到这个错误。这会阻止苹果接受应用程序吗?如何修复?

  2012-07-26 01:58:18.621 Rolo [33597:11303]无法同时满足约束。 
以下列表中的至少一个约束可能是您不想要的。尝试这样:(1)看每个约束,并尝试找出你不期望的; (2)找到添加了不需要的约束或约束的代码并进行修复。 (注意:如果您看到您不明白的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性的文档翻译AutotoresizingMaskIntoConstraints)

< 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:0x72b f7c0] - (NSSpace(8)) - [UIButton:0x886efe0]>,
< NSLayoutConstraint:0x72c1570 UIRoundedRectButton:0x72bbc10.baseline == UIRoundedRectButton:0x7571170.baseline>,
< NSLayoutConstraint:0x72c21f0 UIRoundedRectButton:0x7571170.top == UIButton:0x886efe0.top> ;


将尝试通过破坏约束恢复
< NSLayoutConstraint:0x72bf860 V:[UILabel:0x72bf7c0(17)]>

打破objc_exception_throw在调试器中捕获这个。
在< UIKit / UIView.h>中列出的UIView上的UIConstraintBasedLayoutDebugging类别中的方法也可能有帮助。


解决方案

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





总是问题是如何找到以下约束和视图。



有两种解决方案:


  1. DEBUG VIEW HIERARCHY >(不推荐这样做)

既然你知道在哪里找到意外的约束(PBOUserWorkDayHeaderView)做得这么好。让我们在红色矩形中找到 UIView NSLayoutConstraint 。因为我们知道他们的 ID在内存中是很容易的。




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






  • 找到正确的UIView:






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





正如你所看到的,内存指针是一样的。所以我们知道现在发生了什么。此外,您可以在视图层次结构中找到 NSLayoutConstraint 。由于它在View中被选中,所以在Navigator中也被选中。





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

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

您可以对调试器指向您的每个约束执行相同操作:-)现在您决定什么与此有关。


  1. 打印更好 (我真的推荐这样,这是Xcode 7)




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





  • 一旦你得到你的 id ,你可以在你的查找导航器






  • ,并快速找到:





如何简单地修复这种情况?




  • 尝试将优先级更改为 999 为破碎的约束。


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:

Always the problem is how to find following Constraints and Views.

There are two solutions how to do this:

  1. DEBUG VIEW HIERARCHY (Do not recommend this way)

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.

  • Stop app using Debug View Hierarchy:

  • Find the proper UIView:

  • The next is to find NSLayoutConstraint we care about:

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. PRINT IT BETTER (I really recommend this way, this is of Xcode 7)

    • set unique identifier for every constraint in your view:

  • 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
    }
}

OBJECTIVE-C

@interface NSLayoutConstraint (Description)

@end

@implementation NSLayoutConstraint (Description)

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

@end

  • build it once again, and now you have more readable output for you:

  • once you got your id you can simple tap it in your Find Navigator:

  • and quickly find it:

HOW TO SIMPLE FIX THAT CASE?

  • try to change priority to 999 for broken constraint.

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

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