加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xcode – 如何找到崩溃约束?

发布时间:2020-12-14 18:00:03 所属栏目:百科 来源:网络整理
导读:有时我会不断收到这样的错误 – 没有任何暗示TextView或Button的含义: 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 an
有时我会不断收到这样的错误 – 没有任何暗示TextView或Button的含义:

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:0x11d748d0 V:[UITextView:0xc1bb000(65)]>","<NSLayoutConstraint:0x11d77620 V:[UIButton:0x11d71cf0(44)]>","<NSLayoutConstraint:0x11d7be30 V:[UIButton:0x11d79e70(43)]>","<NSLayoutConstraint:0xa1980d0 V:|-(134)-[UITextView:0xc1bb000]   (Names: '|':UIView:0xa1afba0 )>","<NSLayoutConstraint:0xa199ed0 UITextView:0xc1bb000.centerY == UIButton:0x11d71cf0.centerY>","<NSLayoutConstraint:0xa199e50 V:[UIButton:0x11d79e70]-(61)-[UIButton:0x11d71cf0]>","<NSLayoutConstraint:0xa199cb0 V:|-(40)-[UIButton:0x11d79e70]   (Names: '|':UIView:0xa1afba0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>

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.

有没有办法识别导致崩溃的代码中的约束?

文本:

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>

遗憾的是没有多大帮助,因为我不知道这在代码中有哪些约束

解决方法

你这样读他们:

<NSLayoutConstraint:0x11d748d0 V:    [UITextView:0xc1bb000(65)]>
 ^ Constraint type  ^ Address  ^Axis ^Description in VFL
                      (of constraint)

所以这是一个约束,迫使textview高达65分.在那里你还有一个约束将这个文本视图固定到其superview的顶部边缘134点:

<NSLayoutConstraint:0xa1980d0 V:|-(134)-[UITextView:0xc1bb000]   (Names: '|':UIView:0xa1afba0 )>

并且约束将文本视图的Y中心固定到按钮的Y中心:

<NSLayoutConstraint:0xa199ed0 UITextView:0xc1bb000.centerY == UIButton:0x11d71cf0.centerY>

并且有一个约束将按钮固定到特定的垂直位置:

<NSLayoutConstraint:0xa199e50 V:[UIButton:0x11d79e70]-(61)-[UIButton:0x11d71cf0]>

你很可能不想要所有这些限制.这里有两个约束,它们试图垂直定位文本视图(基于按钮,并基于超视图顶部的绝对间距).

在应用程序的某个位置,您必须拥有一个带有文本字段和两个按钮的视图.如果你打破所有例外,你可以注销日志中给出的各种地址,如果你不确定,可以找出超级视图等,但希望你能够从中解决这个问题.

有时将日志复制到文本编辑器并使用单词查找/替换地址以便于阅读更有帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读