Making a UICollectionView continuously scroll

Viewed 8554

I have a game where I need to have a board of letters continuously scrolling, and looping through a set of data (A, D, X, S, R, P, F, G, H, Y, W, M) (Like this: https://www.youtube.com/watch?v=z3rO8TbkS-U&feature=youtu.be). When a user taps on a letter, the letter needs to be removed from the board. I can't have the board stop scrolling, it needs to continuously scroll.

I'm not exactly sure how to do this. I've been trying to do this with a UICollectionView, but I'm not exactly sure how to do this.

Any help would be greatly appreciated! Thanks :)

2 Answers

I implement this in StableCollectionViewLayout.

It is based on the UICollectionViewLayout subclass using methods

override open func prepare(forCollectionViewUpdates updateItems: [UICollectionViewUpdateItem]) {
super.prepare(forCollectionViewUpdates: updateItems)

// there is possible to calculate a content offset the difference
// with the help layout attributes for each updated item or only visible items
    self.offset = calculate(...)
}

override open func finalizeCollectionViewUpdates() {
    super.finalizeCollectionViewUpdates()
    self.offset = nil
}

override open func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
    // there is necessary to add difference to/instead proposedContentOffset
    if let offset = self.offset {
       return offset
    }
    return proposedContentOffset
}
Related