gpt4 book ai didi

ios6 - initialLayoutAttributesForAppearingItemAtIndexPath 为所有可见单元格触发,而不仅仅是插入的单元格

转载 作者:行者123 更新时间:2023-12-03 13:24:36 25 4
gpt4 key购买 nike

有没有人看到这个问题的体面答案?
initialLayoutAttributesForAppearingItemAtIndexPath似乎正在为所有可见的单元格调用,而不仅仅是插入的单元格。根据Apple's own docs :

For moved items, the collection view uses the standard methods to retrieve the item’s updated layout attributes. For items being inserted or deleted, the collection view calls some different methods, which you should override to provide the appropriate layout information



这听起来不像正在发生的事情......其他单元格没有被插入,它们正在被移动,但它正在调用 initialLayoutAttributesForAppearingItemAtIndexPath对于那些 正在移动 也。

我见过使用 prepareForCollectionViewUpdates: 的变通方法跟踪哪些 indexPaths 正在更新并且只更改那些,但这似乎有点奇怪,因为它会再次出现在他们自己的文档中。有没有其他人找到解决这个问题的更好方法?

最佳答案

我找到了this blog post by Mark Pospesel乐于助人。
作者还修复了 WWDC CircleLayout sample 和 posted it on Github .

感兴趣的方法:

- (void)prepareForCollectionViewUpdates:(NSArray *)updateItems
{
// Keep track of insert and delete index paths
[super prepareForCollectionViewUpdates:updateItems];

self.deleteIndexPaths = [NSMutableArray array];
self.insertIndexPaths = [NSMutableArray array];

for (UICollectionViewUpdateItem *update in updateItems)
{
if (update.updateAction == UICollectionUpdateActionDelete)
{
[self.deleteIndexPaths addObject:update.indexPathBeforeUpdate];
}
else if (update.updateAction == UICollectionUpdateActionInsert)
{
[self.insertIndexPaths addObject:update.indexPathAfterUpdate];
}
}
}

- (void)finalizeCollectionViewUpdates
{
[super finalizeCollectionViewUpdates];
// release the insert and delete index paths
self.deleteIndexPaths = nil;
self.insertIndexPaths = nil;
}

// Note: name of method changed
// Also this gets called for all visible cells (not just the inserted ones) and
// even gets called when deleting cells!
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
// Must call super
UICollectionViewLayoutAttributes *attributes = [super initialLayoutAttributesForAppearingItemAtIndexPath:itemIndexPath];

if ([self.insertIndexPaths containsObject:itemIndexPath])
{
// only change attributes on inserted cells
if (!attributes)
attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath];

// Configure attributes ...
attributes.alpha = 0.0;
attributes.center = CGPointMake(_center.x, _center.y);
}

return attributes;
}

// Note: name of method changed
// Also this gets called for all visible cells (not just the deleted ones) and
// even gets called when inserting cells!
- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
// So far, calling super hasn't been strictly necessary here, but leaving it in
// for good measure
UICollectionViewLayoutAttributes *attributes = [super finalLayoutAttributesForDisappearingItemAtIndexPath:itemIndexPath];

if ([self.deleteIndexPaths containsObject:itemIndexPath])
{
// only change attributes on deleted cells
if (!attributes)
attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath];

// Configure attributes ...
attributes.alpha = 0.0;
attributes.center = CGPointMake(_center.x, _center.y);
attributes.transform3D = CATransform3DMakeScale(0.1, 0.1, 1.0);
}

return attributes;
}

关于ios6 - initialLayoutAttributesForAppearingItemAtIndexPath 为所有可见单元格触发,而不仅仅是插入的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13498052/

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