CollectionView control

0

I am developing a game for iPhone with Swift 4 . My problem is this: I have a% co_of% of 10 columns and enough rows, more than 70, so in the iPhone screen only 12 rows of the more than 70 are displayed) We put ourselves in situation:

1.- the rows from 5 to 17 (for example) are visible in the iPhone screen

2.- the player presses one of the visible cells (or press a button on the screen)

3.- In response to that click I want the iPhone screen to move the CollectionView so that the rows from 42 to 54 (for example) are visible on the screen

And this is my problem: I do not know how to make the "focus" of CollectionView be positioned in the rows that I intend to see on the screen.

    
asked by Edu Ardo 10.05.2018 в 10:57
source

1 answer

0

To move a scrollview or a tableview, you must generate the indexpath you want to move to and then indicate it to the collectionView or tableView. You will know which cell you want to go to, and you generate the indexpath with

let ip = IndexPath(row: xxx, section: yyy)

and to move the collectionView

collectionView.scrollToItem(at: ip, at: .centerHorizontally, animated: true)

or for a tableView

tableView.scrollToRow(at: ip, at: .top, animated: true)

From there you can continue investigating this option

    
answered by 10.05.2018 / 12:35
source