菜鸟教程小白 发表于 2022-12-11 20:20:41

ios - 如何调整 UIView 的 Y anchor ?


                                            <p><p>我可以用什么来替换 anchor 以将 inputContainerView 提高一点。目前它的中心看起来不正确。</p>

<p>这是我所拥有的代码:</p>

<pre><code>inputsContainerView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
inputsContainerView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>有一个额外的参数可以相对于另一个 View 调整 anchor 。请使用自动完成功能并仔细阅读建议及其描述。示例:</p>

<pre><code>inputsContainerView.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 10).isActive = true
inputsContainerView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -10).isActive = true
</code></pre>

<p>将 10 或 -10 替换为适合您要求的值。约束的 <strong>constant</strong> 参数相对于提到的 anchor 移动 anchor 。 </p>

<hr/>

<p><em>提示:</em><strong>负</strong>值将您的 anchor <strong>向上</strong>移动为水平 anchor ,向<strong>左侧</strong>移动垂直 anchor 。正值则相反。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何调整 UIView 的 Yanchor ?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/51220809/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/51220809/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何调整 UIView 的 Y anchor ?