【问题标题】:How do I recreate the rename animation in Pages with a UICollectionView?如何使用 UICollectionView 在 Pages 中重新创建重命名动画?
【发布时间】:2012-10-06 16:29:55
【问题描述】:

In Pages 文档以纸张大小的矩形列出,下方带有标题和日期。我用 UICollectionView 重新创建了这个外观。

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

(我发现 this video 显示了我在说什么)

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

【问题讨论】:

    标签: ios core-animation uicollectionview


    【解决方案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

    【讨论】:

    • 我没有机会尝试这个,但好主意。我最终在单元格中放置了一个 UITextField 并进行了内联重命名。如果用户滚动集合视图,我只需关闭键盘。最终使用新的非页面设计效果更好。
    猜你喜欢
    • 2018-08-11
    • 2023-03-25
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 2013-05-21
    • 2014-09-30
    • 2013-12-19
    • 1970-01-01
    相关资源
    最近更新 更多