简体   繁体   English

相同数据的不同视图之间过渡的概念

[英]Concept for transition between different views of the same data

I have data in a grid and as soon as the user touches an item the layout should change and the items animate to the new layout. 我在网格中有数据,一旦用户触摸某个项目,布局便会更改,并且该项目会以新布局动画。

在此处输入图片说明

I am currently using the UICollectionViewFlowLayout for the grid. 我目前正在使用UICollectionViewFlowLayout作为网格。 Naturally I could just add new views for the strip at the bottom and the detail view at the top, but I want to animate the items from the grid to the strip. 自然,我可以在底部添加新的视图,在顶部添加详细视图,但是我想为网格中的项目设置动画。

Can I elegantly achieve this behaviour using UICollectionViewFlowLayout or do I have to create a custom Layout and custom transitions for this (Which is what I would like to avoid). 我可以使用UICollectionViewFlowLayout优雅地实现此行为,还是必须为此创建自定义布局和自定义过渡(我想避免这种情况)。

The most durable way to do this would be to subclass UICollectionViewLayout for the second layout. 最持久的方法是将UICollectionViewLayout子类UICollectionViewLayout第二个布局。 However, you may be able to do this without subclassing, although it probably will seem more complicated. 但是,您可能无需子类化就可以做到这一点,尽管它看起来似乎更加复杂。

The idea is to copy out the contents of the green cell and animate them into place above the collection view - not a cell in the collection view. 这个想法是复制绿色单元格的内容并将其设置为动画,使其位于集合视图上方 ,而不是集合视图中的单元格。 You'd get the frame of the starting point of the animation using [collectionView layoutAttributesForItemAtIndexPath:selectedIndexPath].frame and adjust for the content offset of the collection view. 您可以使用[collectionView layoutAttributesForItemAtIndexPath:selectedIndexPath].frame动画起点的帧,并调整集合视图的内容偏移量。 Of course, you'd then have to delete the green cell from the collection view using [collectionView deleteItemsAtIndexPaths:@[selectedIndexPath]] . 当然,您必须使用[collectionView deleteItemsAtIndexPaths:@[selectedIndexPath]]从集合视图中删除绿色单元格。

In the meantime, create another instance of UICollectionViewFlowLayout . 同时,创建另一个UICollectionViewFlowLayout实例。 This instance would have scrollDirection set to horizontal. 该实例会将scrollDirection设置为水平。 In your UICollectionViewDelegateFlowLayout methods, set the inset for the section to the area you want to display the cells in - ie, a very large value for top .(You wouldn't have to set the collection view frame.) You would then transition to this layout. UICollectionViewDelegateFlowLayout方法中,将部分的插图设置为要在其中显示单元格的区域-即, top值非常大。(您不必设置集合视图框架。)然后,您可以过渡到这种布局。

I think you'll find that subclassing UICollectionViewLayout is going to be more straightforward and encapsulated. 我想您会发现, UICollectionViewLayout子类将更加直接和封装。 If you want to recreate this presentation in another context, for instance, it would be much easier to do so with a subclassed layout. 例如,如果要在另一个上下文中重新创建此演示文稿,则使用子类化的布局会更容易。

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

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