代码之家  ›  专栏  ›  技术社区  ›  Pranav Wadhwa

UICollectionView中移动的自动布局约束

  •  0
  • Pranav Wadhwa  · 技术社区  · 7 年前

    我正在开发一个应用程序,它使用UICollectionView,单元格可以垂直滚动。我已经用AutoLayout设置了大部分界面。以下是自动布局设置:

    AutoLayout

    然而,卷轴不会产生我想要的结果。有时,约束会变得混乱 GradientView TextView Here is a video displaying the scrolling effect.

    Expectation

    Reality

    背景中的紫色是 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()
    }
    

    滚动时更改约束的可能原因是什么?提前谢谢。

    1 回复  |  直到 7 年前
        1
  •  0
  •   sRoy    7 年前

    GradientView顶部,左侧,右侧将是零(0)与您的主按钮和GradientView底部将是大约30(根据您的需要)文本视图。 与TextView相同。左,右,底部将是0与您的主按钮和顶部将是30梯度视图。