UICollectionView:如何定义一个支持水平和垂直滚动的UICollectionViewLayout? [英] UICollectionView: How to define a UICollectionViewLayout that supports horizontally and vertically scrolling?
问题描述
目前我正在尝试创建一个 UICollectionView
,它应该显示一个简单的 excel-like-spreadsheet
,带有 rows
和列
.我相信,使用 UICollectionViews
应该是一件容易的事.我真的很想在 UICollectionView
中实现,而不是在任何 grid framework
中.
At the moment I'm trying to create an UICollectionView
, that should display a simple excel-like-spreadsheet
, with rows
and columns
. This should be an easy task with UICollectionViews
, I believed. And I really would like to do the implementation in UICollectionView
, not in any grid framework
.
但目前我有点悬.我发现,不幸的是我不能使用 UICollectionViewDelegateFlowLayout
,因为它只支持 either horizontally 中的
scrolling
或 vertically
方向.但我需要双向滚动
.
But at the moment I'm hanging a little bit. What I've figured out is, that I unfortunately can't use a UICollectionViewDelegateFlowLayout
, because this only supports scrolling
in either horizontally
or vertically
direction. But I need scrolling
in both directions.
因此我必须使用一个UICollectionViewLayout
,但是我没有找到好的例子,如何使用它.你们有没有一个例子,如何继承 UICollectionViewLayout
以支持 rows
和 columns
?
Therefore I have to use a UICollectionViewLayout
, but for this I didn't find good examples, how to use it. Has anyone of you an example, how to subclass an UICollectionViewLayout
to support rows
and columns
?
提前致谢.
推荐答案
我添加了一个使用自定义布局来实现简单水平 &此处垂直滚动网格 https://github.com/neildavis/MyCollectionView
I've added an example of using a custom layout to implement a simple horizontal & vertical scrolling grid here https://github.com/neildavis/MyCollectionView
我的示例使用 PSTCollectionView,因为我需要 iOS 5 支持,但它的 API 与内置的 UICollectionView 兼容.(实际上它使用提供的兼容性类(PSUICollectionView 等)来确保它在 iOS 6 上使用 UICollectionView 并在 iOS 5 上回退到使用 PSTCollectionView 等.)只需删除这些上的PS"前缀即可恢复为仅 iOS 6 的 UIKit 实现.
My example uses PSTCollectionView since I needed iOS 5 support, but it's API compatible with built in UICollectionView. (Actually it uses the compatibility classes (PSUICollectionView etc) provided to ensure it uses a UICollectionView on iOS 6 and falls back to using PSTCollectionView etc on iOS 5.) Just remove the 'PS' prefix on these to revert to iOS 6 only UIKit implementation.
这篇关于UICollectionView:如何定义一个支持水平和垂直滚动的UICollectionViewLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!