ios - 滚动直到 uicollectionview 的最后一个单元格

标签 ios swift uicollectionview cell collectionview

我在滚动 collectionView 时遇到问题 选择单元格后,最后一个单元格不可选择 under this cell there is another cell but there is not any space for scrolling

unavailable last cell can not scroll to reach it

   func changeViewSize(from: CGFloat, to: CGFloat, indexPath: IndexPath) {
    UIView.transition(with: myCollection, duration: 0.5, options: .beginFromCurrentState, animations: {() -> Void in
        let cell = self.myCollection.cellForItem(at: indexPath)!
        let cellCenter = CGPoint(x: cell.center.x, y: cell.center.y + 50)
        if cell.bounds.height == from {
            let sizee = CGRect(x: cell.center.x, y: cell.center.y, width: cell.frame.width, height: to)
            self.myCollection.cellForItem(at: indexPath)?.frame = sizee
            self.myCollection.cellForItem(at: indexPath)?.center = cellCenter
            for x in self.indexPathss {
                if x.row > indexPath.row {
                    print("this is cells")
                    print(self.myCollection.visibleCells)
                    let cell = self.myCollection.cellForItem(at: x)!
                    cell.center.y += 100
                }
            }
        }
    }, completion: {(_ finished: Bool) -> Void in
        print("finished animating of cell!!!")
    })
}

最佳答案

您似乎正在手动更改单元格大小和位置。 UICollectionView 不会意识到这些变化,因此它的大小不会改变。最后的单元格只是移出了 Collection View 的可见区域。

我以前没有做过类似的事情,但是看看 performBatchUpdates(_:completion:) 。我会尝试使用该方法重新加载您想要增大的单元格。您的布局必须提供正确的属性,即大小。

从屏幕截图来看,也许您可​​以使用 UITableView 来代替?如果有可能的话,事情可能会简化。它还具有 performBatchUpdates(_:completion:) 方法,并且 UITableViewDelegate 必须提供正确的 heights for the rows .

关于ios - 滚动直到 uicollectionview 的最后一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48856543/

相关文章:

ios - 获取从tableview Swift单击的按钮上的标签值

ios - 阻止 SKSpriteNode 离开 View (Swift)

ios - 过滤和排序 swift 数组

ios - Collection View 单元格未出现在 Collection View 中?

ios - 为 UICollectionViewLayout 使用失效上下文

ios - SWIFT:通过单击 UIButton 将节/行插入 UICollectionView

ios - Swift:使用 Localizable.stringsdict 的本地化字符串中的千位分隔符

ios - 定位自定义 MKAnnotationView

ios - 三 Sprite 节点碰撞

swift - 为什么 Swift NIO 示例使用 HTTP/2 到 HTTP/1 协议(protocol)转换?