Animation IOS:设置UICollectionViewCells的动画以在更改方向时滑动

Animation IOS:设置UICollectionViewCells的动画以在更改方向时滑动,animation,ios6,uiinterfaceorientation,uicollectionview,uicollectionviewlayout,Animation,Ios6,Uiinterfaceorientation,Uicollectionview,Uicollectionviewlayout,我希望覆盖我的UICollectionViewFlowLayout,以便在由于方向改变而改变位置时使单元格滑动。我目前拥有的是纵向的每行3个单元格,横向的每行4个单元格,但我能得到的唯一动画是当我改变方向时默认的淡入 我一直在研究如何使用performbatchUpdate,但我很确定这不是我能找到答案的地方 我还研究了layouttributesforelementincrect和layouttributesforeitematindexpath,我想这就是我可以找到答案的地方。我不确定是否需

我希望覆盖我的
UICollectionViewFlowLayout
,以便在由于方向改变而改变位置时使单元格滑动。我目前拥有的是纵向的每行3个单元格,横向的每行4个单元格,但我能得到的唯一动画是当我改变方向时默认的淡入

我一直在研究如何使用
performbatchUpdate
,但我很确定这不是我能找到答案的地方

我还研究了
layouttributesforelementincrect
layouttributesforeitematindexpath
,我想这就是我可以找到答案的地方。我不确定是否需要为单元格创建新属性(
previousCenter
可能),并将其用作新动画的起点,或者使用
performBatchUpdates
将新帧作为要更改的值

作为记录,我发现的所有动画问题都是关于如何更改动画以插入和删除项目,这不是我想要做的

试一试

然后添加任何你需要的东西来“滑动”它

如果您使用的是flowLayout或其子类,它会自动为您重新定位单元格。如果您使用了layout子类,则可能需要调整您返回的LayoutAttribute以与旋转相对应。动画应该为您完成

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(    NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    [self.collectionView reloadData];
}