菜鸟教程小白 发表于 2022-12-12 12:24:29

ios - Collectionview 的底部约束未在运行时更新


                                            <p><p>我正在使用带有 FlowLayout 的 collectionView。请找到以下图片。 </p>

<p> <a href="/image/sk2tX.png" rel="noreferrer noopener nofollow"><img src="/image/sk2tX.png" alt="enter image description here"/></a> </p>

<p>图中,白色区域是collectionView。在运行时,红色 View 可能会根据条件隐藏。所以 collectionView 将不得不向上移动。那不是问题。这按预期工作。但是当collectionView向上移动时,通过20像素的垂直间距约束连接到collectionView的'All Months'按钮不会向上移动。</p>

<p> <a href="/image/cNaXK.png" rel="noreferrer noopener nofollow"><img src="/image/cNaXK.png" alt="enter image description here"/></a> </p>

<p>我的要求是“所有月份”按钮必须在 collectionView 旁边 20 像素,即使 collectionView 在运行时更改其 y 位置或高度也是如此。 </p>

<p>编辑:
我已将 ScrollView 的 contentView 向上移动,以向您显示“所有月份”和“下一步”按钮的约束。请检查以下图片</p>

<p> <a href="/image/7OcUR.png" rel="noreferrer noopener nofollow"><img src="/image/7OcUR.png" alt="enter image description here"/></a>
<a href="/image/zPcxr.png" rel="noreferrer noopener nofollow"><img src="/image/zPcxr.png" alt="enter image description here"/></a> </p>

<p> <a href="/image/5elS3.png" rel="noreferrer noopener nofollow"><img src="/image/5elS3.png" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在查看和编辑您的项目后,我正在更改整个答案,这里是我从您的项目中 fork 的编辑链接:</p>

<p> <a href="https://github.com/subhajitregor/AutoLayoutTest" rel="noreferrer noopener nofollow">https://github.com/subhajitregor/AutoLayoutTest</a> </p>

<p>我改变的东西:</p>

<ol>
<li><p> ScrollView 中的内容 View ,其高度限制优先级更改为 250(低优先级),因为如果您的橙色 View 被隐藏,它不会变短。</p></li>
<li><p>在您的 <code>viewWillAppear()</code> 中我添加了 <code>self.view.layoutIfNeeded()</code> 并注释掉了 <code>viewDidLayoutSubviews()</code> 的内部</code>(您可以根据需要重新打开代码)</p></li>
</ol>

<p>我已根据需要检查了它及其工作。请检查我提供的链接中的项目并告诉我。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Collectionview 的底部约束未在运行时更新,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40779026/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40779026/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Collectionview 的底部约束未在运行时更新