菜鸟教程小白 发表于 2022-12-11 18:31:42

ios - Swift Xcode 会尝试通过打破约束来恢复吗?


                                            <p><p>当我用 Swift 4 开发我的应用程序午餐时,我在 xCode 日志上收到消息,我的 tableview 有多个不同的单元格,大约 12 个不同的单元格,我收到的警告消息是:</p>

<pre><code>Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in &lt;UIKit/UIView.h&gt; may also be helpful.
2017-08-21 09:27:57.404497+0300 muzeit Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don&#39;t want.
    Try this:
      (1) look at each constraint and try to figure out which you don&#39;t expect;
      (2) find the code that added the unwanted constraint or constraints and fix it.
(
    &#34;&lt;NSLayoutConstraint:0x174481770 V:|-(0)-   (active, names: &#39;|&#39;:UIView:0x107a09d10 )&gt;&#34;,
    &#34;&lt;NSLayoutConstraint:0x174481860 V:-(-60)-|   (active, names: &#39;|&#39;:UIView:0x107a09d10 )&gt;&#34;,
    &#34;&lt;NSLayoutConstraint:0x1744818b0 UIImageView:0x107a09eb0.centerY == UIView:0x107a09d10.centerY   (active)&gt;&#34;
)

Will attempt to recover by breaking constraint
&lt;NSLayoutConstraint:0x1744818b0 UIImageView:0x107a09eb0.centerY == UIView:0x107a09d10.centerY   (active)&gt;

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in &lt;UIKit/UIView.h&gt; may also be helpful.
2017-08-21 09:27:57.492890+0300 muzeit Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don&#39;t want.
    Try this:
      (1) look at each constraint and try to figure out which you don&#39;t expect;
      (2) find the code that added the unwanted constraint or constraints and fix it.
(
    &#34;&lt;NSLayoutConstraint:0x17048b770 V:|-(0)-   (active, names: &#39;|&#39;:UIView:0x107a30a90 )&gt;&#34;,
    &#34;&lt;NSLayoutConstraint:0x17048b860 V:-(-60)-|   (active, names: &#39;|&#39;:UIView:0x107a30a90 )&gt;&#34;,
    &#34;&lt;NSLayoutConstraint:0x17048b8b0 UIImageView:0x107a30c30.centerY == UIView:0x107a30a90.centerY   (active)&gt;&#34;
)
</code></pre>

<p>我试图用谷歌搜索它以找到一些解决方法,我找不到明确的答案,而且断点也没有显示约束有问题! </p>

<p>有什么想法吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果您想更好地了解日志试图告诉您的内容,您可以查看 <a href="https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage.html#//apple_ref/doc/uid/TP40010853-CH27-SW1" rel="noreferrer noopener nofollow">Visual Format Language</a> .您可以按如下方式“翻译”您的日志:</p>

<p><code>V:|-(0)-</code> = 在父 View 的顶部 (|) 和 ImageView 之间设置一个 0 点的垂直 (V:) 空间</p >

<p><code>V:-(-60)-|</code> = 在 UIImageView 底部和父 View(|) 之间设置 -60 点的垂直 (V:) 空间</p>

<p><code>UIImageView:0x107a09eb0.centerY == UIView:0x107a09d10.centerY (active)</code> = 垂直居中 UIImageView 到 superview</p>

<p>通过翻译,现在更容易理解你的 UIImageView 被固定在顶部和底部,这与第三个约束冲突,即试图垂直居中 UIImageView。 </p>

<p>正如@ReinerMeilan 在评论中所建议的,您可以删除 centerY 约束来解决此自动布局问题。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Swift Xcode 会尝试通过打破约束来恢复吗?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/45790601/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/45790601/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Swift Xcode 会尝试通过打破约束来恢复吗?