gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:48:10 26 4
gpt4 key购买 nike

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

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

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

使用 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

关于ios - 如何使用 UICollectionView 在 Pages 中重新创建重命名动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12761574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com