是否可以将UICollectionView缩放为一个单元? [英] Is it possible to zoom UICollectionView as a unit?

查看:116
本文介绍了是否可以将UICollectionView缩放为一个单元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在最新项目中有一个关卡视图。它包括作为UICollectionViewCells的级别标记和用于有趣装饰的各种UICollectionReusableView。

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

我们希望能够放大/缩小(这是一张大地图)。我希望我可以使用内部UIScrollView来实现这一点,但是,你不能自己缩放......只是一个子视图。

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.

推荐答案

你有没有想过嵌入UIScrollView中的UICollectionView?
这听起来有点简单,但
我遇到了类似的问题,尝试了这个,是的,它确实有效。

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.

你必须设置框架UICollectionView到它自己的上下文大小
(从你的UICollectionViewLayout调用collectionViewContentSize),
所以collectionView不再滚动了。
它也禁用了所有的单元重用,所以这可能不是你想要的。
但另一方面,有一些用例,它更便宜,更快,
预先渲染所有视图,而不是每次滚动都要调用dequeueReusableCellWithReuseIdentifier:
。也许你的地图应用程序可以从这样的东西中受益。

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.

我确信有更复杂的解决方案可能,外部滚动视图
只进行缩放并且集合视图负责滚动。
也许子类化UIScrollView并为panGestureRecognizer返回nil可以工作,
但这只是猜测。

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.

这篇关于是否可以将UICollectionView缩放为一个单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆