ios - Swift UICollectionViewLayout contentSize 崩溃
<p><p>尝试在 iOS 中调整 4"屏幕上的 Collection View 的内容大小,但我在控制台中收到关于使用 Collection View 流布局的宽度的错误。</p>
<pre><code> if DeviceType.IS_4_INCH {
collectionView.contentSize = CGSize(width: screenWidth - 50, height: collectionView.collectionViewLayout.collectionViewContentSize.height)
}
</code></pre>
<p>错误:</p>
<pre><code>The relevant UICollectionViewFlowLayout instance is
<UICollectionViewFlowLayout: 0x7fbb9144dd20>, and it is attached to
<UICollectionView: 0x7fbb92885800; frame = (10 10; 270 750); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fbb914d25e0>; layer = <CALayer: 0x7fbb9147f560>; contentOffset: {0, 0}; contentSize: {325, 750}> collection view layout:
<UICollectionViewFlowLayout: 0x7fbb9144dd20>.
</code></pre>
<p>当框架为 270 时,我发现问题与内容大小 (325) 有关,但当我尝试根据屏幕宽度更改它时,它会崩溃。</p>
<p>谢谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在调整框架大小后,您的某个元素看起来超出了 UICollectionView 的大小</p>
<p>在重新加载数据之前尝试使当前布局无效:</p>
<pre><code>self.collectionView.collectionViewLayout.invalidateLayout()
</code></pre></p>
<p style="font-size: 20px;">关于ios - Swift UICollectionViewLayout contentSize 崩溃,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/45796646/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/45796646/
</a>
</p>
页:
[1]