Is it possible to zoom UICollectionView as a unit?

别说谁变了你拦得住时间么 提交于 2020-01-02 06:20:45

问题


We have a level map view in our latest project. It includes the level markers as UICollectionViewCells and various UICollectionReusableViews for fun decoration.

We would like to be able to zoom in / out (it is a big map). I had hoped I could make use of the internal UIScrollView to do so, however, you can't zoom yourself... only a subview.

Is there anyway to do this outside of individually scaling and relocating each element as I zoom? Feels like it should be a common thing and thus a more 'built in' solution available.


回答1:


Have you thought about embedding the UICollectionView in a UIScrollView? It sounds somewhat simple, but I ran in a similar problem, tried this and, yes it worked.

You have to set the frame of the UICollectionView to its own context size (calling collectionViewContentSize from your UICollectionViewLayout), so the collectionView does not scroll anymore. It disables all the cell reuse stuff too, so this is maybe not what you want. But on the other side, there are use cases, where it's cheaper and faster, to have all the views rendered beforehand than having to call dequeueReusableCellWithReuseIdentifier: with every scroll movement. Maybe your map application could benefit from something like that.

I am sure there are more sophisticated solutions possible, where the the outer scroll view only does the zooming and the collection view is responsible for scrolling. Maybe subclassing UIScrollView and returning nil for the panGestureRecognizer could work, but this is just a guess.



来源:https://stackoverflow.com/questions/19667398/is-it-possible-to-zoom-uicollectionview-as-a-unit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!