【问题标题】:which is the best way to implement the offset in collection view?在集合视图中实现偏移的最佳方法是什么?
【发布时间】:2019-09-27 16:27:32
【问题描述】:

我需要在我的第一列中实现偏移。我明白了,但是当我滚动到视图中时,最后一个单元格仍然移动到底部。每次滚动都会发生这种情况。

我的代码是下一个。

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let identifier = "Cell"
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! cellFavoriteTransferCollectionViewCell
    cell.titleName.text = "hola"
    cell.hero.id = "Cell\(indexPath.row)"
    if indexPath.row % 2 == 0 {
        cell.frame = CGRect(x: cell.frame.origin.x, y: cell.frame.origin.y + 50, width: cell.frame.width, height: cell.frame.height)
    } else {
        cell.frame = CGRect(x: cell.frame.origin.x, y: cell.frame.origin.y, width: cell.frame.width, height: cell.frame.height)
    }

    return cell
}

我的错误是什么?由于最后一个单元格显示为一半,我必须如何更改垂直滚动大小?

【问题讨论】:

    标签: ios swift uicollectionviewcell collectionview


    【解决方案1】:

    您需要自定义单元格布局属性。

    关注这个 tuts 可能会帮助您解决问题:https://www.raywenderlich.com/4829472-uicollectionview-custom-layout-tutorial-pinterest

    【讨论】:

      猜你喜欢
      • 2020-10-01
      • 2011-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多