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また、値が変更されたときにレイアウトを無効にする必要があります(セッターで行います)。名前の変更が終了 (またはキャンセル) したら、renameIndexPath背面を に変更しnilます。

于 2012-10-11T13:03:51.840 に答える