0

I'd like to add reflection to my collection view's cells. I have the method that creates a reflection, but I don't know the correct time to create the snapshot.

I have tried doing it in the collection view's -viewWillAppear:, but the cell's contentView has zero-sized frames for its subviews. I have also tried taking the snapshot during the cell's -layoutSubviews, but the subview frames are still 0.

At what point is the cell's layout set so I can take the snapshot?

4

1 回答 1

0

应在将单元格添加到集合视图之后以及在集合视图数据源将单元格出列之后拍摄快照。这可以确保快照是最新的,在正确的时刻包含单元格的内容视图(当它即将被添加到集合视图时,并且在它刚刚出列之后):

CollectionViewCell.m

- (void)didMoveToSuperview {
    [self updateSnapshotImage];
}

CollectionViewController.m

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];
    [cell updateSnapshotImage];
    return cell;
}
于 2013-07-09T14:16:10.583 回答