Post

Replies

Boosts

Views

Activity

Reply to orthogonalScrollingBehavior paging - getting current cell in center
I was able to use the answer andy_ gave. I stored my offset to a CGFloat variable. section.visibleItemsInvalidationHandler = { [weak self] (visibleItems, scrollOffset, environment) in    self?.currentScrollOffset = scrollOffset.x } I was then able to calculate the current cell being viewed by getting the cell width from the layout, taking into account insets, and calculating where the current scroll offset is. The index path I used was one known to exist, just for getting an accurate cell width. let inset:CGFloat = 6 let indexPath = IndexPath(item: 0, section: 0) if let attr = collectionView.layoutAttributesForItem(at: indexPath) {   let cellWidth = attr.bounds.width   let centerCell = cellWidth / 2   let result = Int((currentScrollOffset + centerCell) / (cellWidth + inset))   print("current index is \(result)") }
Jun ’20