2

在 Pages 中,文档被列为纸张大小的矩形,下面有标题和日期。我用 UICollectionView 重新创建了这个外观。

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

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

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

4

1 回答 1

1

你必须继承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.

于 2012-10-11T13:03:51.840 回答