iOS / Swift |(iOS / Swift | Infinite matrice of views : ScrollView or CollectionView?)

我正在创造一个无限的“矩阵”的观点。 当我加载我的MainView时,我创建了它周围的视图。 然后,如果我滚动到右视图,我会围绕右视图创建新视图。

我试图模式化我想做的事情:

我问了两个问题:

1-我应该使用ScrollView并在其中添加视图还是在CollectionView中添加collectionViewCells(其大小为MainView)? 哪一个更好,为什么? 我打算使用ScrollView和视图,但CollectionView允许可重复使用的单元,这些单元可能非常强大,具有无限矩阵......

2-由于用户可以滚动顶部和左侧,如何设置在“索引-1”处添加views / collectionViewCells 而不重新加载或移动所有内容

I'm creating a infinite "matrix" of views. When I load my MainView, i create views around it. Then, if I scroll to the right view for example, I create new views around the right view.

I tried to schematize what I want to do :

I'm asking 2 questions :

1- Should I use ScrollView and add views in it OR a CollectionView and add collectionViewCells (with size of MainView) in it ? Which one is better and Why ? I was going to use ScrollView and views but CollectionView allows reusable cells which could be very powerful with infinite matrix ...

2- Since User can scroll Top and Left, How do you manage to add views / collectionViewCells at "index -1" without reloading or moving everything ?

最满意答案

都不是。 创建自己的UIView子类,它有一个UIPanGestureRecognizer 。 识别平移时,更新子视图的位置。 添加和删​​除边缘的孩子,这样你就不会有太多的孩子。 (当视图移动到屏幕外时,您可以removeFromSuperview )。

Neither. Create your own UIView subclass which has a UIPanGestureRecognizer. When the pan is recognized, update the position of your child views. Add & remove children around the edges, so that you never have too many children. (As views move offscreen, you can removeFromSuperview).

更多推荐