简体   繁体   English

如何制作“卡片叠”类的UICollectionView?

[英]How do I make a 'card stack' kind of UICollectionView?

I'd really like to do something similar to Tinder's "pile of cards" interface, but with a UICollectionView. 我真的很想做一些与Tinder的“纸牌堆”界面类似的事情,但是要使用UICollectionView。

I would assume that if you need the other cells to dynamically move given the cell you are interacting with, one would be in Edit Mode on a UICollectionView, but I'm not sure. 我假设如果给定要与之交互的单元格而需要其他单元格动态移动,则其中一个将处于UICollectionView的“编辑模式”下,但我不确定。

Please don't reply with specific Cocoapods that do this and "why don't I just use those?"; 请不要以特定的Cocoapods回答,“我为什么不只使用它们呢?”; it goes beyond just that. 不仅如此。 I have all sorts of content, and this is just one of the layouts / presentation types I need. 我有各种各样的内容,这只是我需要的布局/演示类型之一。 Sometimes it's a grid. 有时是网格。 A lot of the controller actions are the same; 许多控制器动作是相同的。 just the display and interaction is different. 只是显示和交互是不同的。

That said, please DO refer me to any code that may already do this, that I could use as a starting point. 就是说,请您参考可能已经做过的所有代码,以作为起点。

Otherwise, I would be grateful to know where I would get started. 否则,我将不胜感激。 I'm thinking maybe one of those projects that re-creates Springboard with a collection view?? 我在想,也许其中一个项目可以用集合视图重新创建Springboard?

EDIT: I was looking for something like a card stack, but not like Tinder in that you can interact with the top card before swiping or letting it return. 编辑:我一直在寻找类似纸牌的东西,但不像Tinder,因为您可以在刷卡或让其归还之前与顶层纸牌进行交互。 In the end what I was trying to accomplish was similar to the old iPod-style 'Cover Flow' view. 最后,我试图完成的工作类似于旧的iPod风格的“ Cover Flow”视图。

I'll try to answer my own post. 我将尝试回答我自己的帖子。 I made a few incorrect assumptions. 我做了一些错误的假设。 In the end it was a lot less complex than I thought. 最后,它没有我想象的那么复杂。

To get a collection view whose layout isn't just 'static within a scrollview' but changes dynamically with the contentOffset property, you need to subclass UICollectionViewLayout and make sure first of all you return YES for - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds 为了获得一个布局视图,它的布局不仅是“滚动视图内的静态”,而且还随着contentOffset属性的变化而动态变化,您需要对UICollectionViewLayout进行子类化,并确保首先为- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds返回YES

from there, most of your heavy lifting will be done in the - (void)prepareLayout method. 从那里开始,大部分繁重的工作都将在- (void)prepareLayout方法中完成。

I basically used the following tutorial as a starting point and kind of followed what they were trying to do (or just downloaded the final project and saw how they did it, and mimicked the same effect), but obviously had a different prepareLayout method: 我基本上以下面的教程为起点,并按照他们想做的事情进行操作(或只是下载了最终项目,并查看了他们是如何做的,并且模仿了相同的效果),但是显然有一个不同的prepareLayout方法:

Ray Wenderlich 雷·温德利希

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM