如何使用UICollectionView在Pages中重新创建重命名动画



在页面中,文档以纸张大小的矩形列出,下面有标题和日期。我已使用UICollectionView重新创建了此外观。

当用户点击标题以重命名文档时,所有其他文档都会淡出,而您点击的文档会从当前位置过渡到中心,并随着键盘的滑出而稍微扩展。

(我发现这个视频显示了我在说什么)

使用UICollectionView时,最好的方法是什么?

您必须对UICollectionViewFlowLayout进行子类化。然后,当执行所需的操作(重命名)时,将需要编辑的单元格的indexPath传递给布局。

然后您可以添加所需的布局属性,如下所示:

-(void)applyRenameAttributes:(UICollectionViewLayoutAttributes *)attributes
{
if (self.renameIndexPath != nil) {
if (attributes.indexPath == self.renameIndexPath) {
// add attributes for the item that needs to be renamed
} else {
attributes.hidden = YES;
}
}
}
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *allAttributes = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *attributes in allAttributes) {
[self applyRenameAttributes:attributes];
}
return allAttributes;
}
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForItemAtIndexPath:indexPath];
[self applyRenameAttributes:attributes];
return attributes;
}

renameIndexPath值更改时,您还需要使布局无效(在setter中执行此操作)。重命名完成(或取消)后,将renameIndexPath更改回nil

最新更新