我正在开发一个应用程序,它使用UICollectionView,单元格可以垂直滚动。我已经用AutoLayout设置了大部分界面。以下是自动布局设置:
然而,卷轴不会产生我想要的结果。有时,约束会变得混乱
GradientView
和
TextView
Here is a video displaying the scrolling effect.
背景中的紫色是
Main Button
. 这个
主按钮
Shadow
位置正确,但
Gradient View
Text View
他们不是。这个
和
我已尝试更新
scrollViewDidScroll
和
cellWillDisplay
方法,但都没有任何效果。
func scrollViewDidScroll(_ scrollView: UIScrollView) {
bigCollection.updateConstraints()
for cell in bigCollection.visibleCells {
cell.updateConstraints()
}
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
cell.updateConstraints()
}
滚动时更改约束的可能原因是什么?提前谢谢。