UICollectionView插入动画单元格后紧跟实际动画单元格

时间:2014-07-01 21:17:46

标签: ios objective-c animation uicollectionview

我为集合视图编写了自定义布局。集合视图的一部分涉及在顶部插入新项目,并从屏幕外开始动画。为了做到这一点,我使用通常的initialLayouts方法。我能够正确地设置对象的动画,但似乎有一个我无法解决的奇怪问题。

我正在制作动画的单元格立即显示在它的最终位置,然后第二个单元格从预期的屏幕外位置动画到位,一旦动画完成就消失。所有我的其他动画删除,边界更改等都很好,所以我不相信我的布局缓存是错误的,正常的布局是完美的。这可能是细胞再利用问题吗?

我创建了一个快速视频演示问题(插入从7秒开始)http://cl.ly/WMei

之前有没有人见过这种行为并且能指出我正确的方向?

不幸的是我无法共享整个布局类,但是这里有我的layoutAttributes方法和初始插入属性,我可以尝试在需要的地方提供更多信息。我很欣赏这是一个很难调试的,所以非常感谢花时间检查它:)。

以下是我申请顶部插入的属性:

  MCLTXGridLayoutAttributes *att = [(MCLTXGridLayoutAttributes*)[self.dataStructure itemAtIndexPath:itemIndexPath] copy];
  att.alpha = 1.0;
  CGRect newFrame = att.frame;
  newFrame.origin.y = self.collectionView.bounds.origin.y - att.totalHeight;
  att.frame = newFrame;
  return att;

和布局属性方法:

    - (UICollectionViewLayoutAttributes*)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
  MCLTXGridLayoutAttributes *att = [MCLTXGridLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
  CGFloat randomTopPadding = (arc4random() % kMaxVerticalSpacing);
  randomTopPadding += kMinVerticalSpacing;
  NSInteger randomExtraPadding = (NSInteger)arc4random() % kOneInXChanceOfRecievingExtraPadding;
  att.topPadding = randomTopPadding + (randomExtraPadding == 1 ? kItemRandomExtraPadding : 0);

  NSUInteger column = [self.dataStructure indexForShortestColumn];
  att.columnIndex = column;

  CGFloat y = MAX(self.tmpCachedHeight, [self.dataStructure heightForColumnWithIndex:column] + kMinItemSpacing) + att.topPadding;

  CGFloat height = [self.datasource collectionView:self.collectionView heightForItemAtIndex:indexPath];
  CGRect frame = CGRectMake([self xOriginForColumn:column], y, self.cachedColumnWidth, height);
  att.frame = frame;
  att.layerPriority = [self.datasource collectionView:self.collectionView layerPriorityForItemAtIndexPath:indexPath];
  att.zIndex = att.layerPriority * -10;
  att.transform3D = CATransform3DIdentity;
  att.transform = CGAffineTransformIdentity;
  return att;
}

1 个答案:

答案 0 :(得分:0)

我最终想到了这一点。我们使用魔法记录,问题来自于保存。

通过我的测试,我创建假对象并使用后台线程进行保存,就像你应该使用MR一样。问题出在我们的网络代码中,完全不小心在主线程上下文中调用了写+保存。这是一个非常小的写入,但它足以扰乱渲染并导致视觉重影效果。

如果您发现此问题并且您正在使用Magical Record或多线程核心数据以及获取的结果控制器等内容,请仔细检查您的保存电话,以确保您不会意外点击主线。

相关问题