在布局更改上设置UICollectionViewCell子视图的动画

时间:2015-06-25 06:44:26

标签: objective-c xcode uicollectionview uicollectionviewcell uicollectionviewlayout

我有两个UICollectionViewLayout,一个用于显示堆叠的单元格,另一个用于在选中时全屏显示单个单元格。

每次选择单元格时,我需要将单元格的子视图设置为某些位置的动画,然后在取消选择单元格时再次移动这些子视图。

第1步:选择了单元格。子视图从原始位置动画到新位置。这里没问题。

第1步:取消选择单元格。子视图动画到另一个位置,但动画从原始位置开始,而不是我在上一步中指示的新位置。

有没有办法保存修改后的状态,并从那里开始制作动画?

更新

以下是我如何更改单元格选择的布局(ViewController.m):

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    __weak CustomCellCollectionViewCell *cell = (CustomCellCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
    // Hide single view
    if ([indexPath isEqual:self.exposedItemIndexPath]) {
        self.exposedItemIndexPath = nil;
        [cell deselectedAnimations];
        [self animateCollectionView:NO];
    }
    // Select single view
    else if (self.exposedItemIndexPath == nil) {
        self.exposedItemIndexPath = indexPath;
        [cell selectedAnimations];
        [self animateCollectionView:YES];
    }
}

- (void)setExposedItemIndexPath:(NSIndexPath *)exposedItemIndexPath
{
    if (![exposedItemIndexPath isEqual:_exposedItemIndexPath]) {
        if (exposedItemIndexPath) {
            self.audiosContentOffset = self.collectionView.contentOffset;
            SelectedLayout *singleLayout = [[SelectedLayout alloc] initWithExposedItemIndex:exposedItemIndexPath.item];
            [self.collectionView setCollectionViewLayout:singleLayout animated:YES];
        }else{
            self.stackedLayout.overwriteContentOffset = YES;
            self.stackedLayout.contentOffset = self.audiosContentOffset;
            [self.collectionView setCollectionViewLayout:self.stackedLayout animated:YES];
            [self.collectionView setContentOffset:self.audiosContentOffset animated:YES];
        }
        _exposedItemIndexPath = exposedItemIndexPath;
    }
}

selectedAnimations 在单元格内移动UIView,当取消选择单元格时, deselectedAnimations 将其移动到其他位置。但是,取消选择的动画从UIView的原始位置开始,而不是从 selectedAnimations 末尾的位置开始。

单元格及其子视图基于nib文件。在我看来,在布局更改时,单元格正在按照nib文件上的“指令”再次渲染,这就是为什么子视图从其原始位置开始动画而不是我将其留在 selectedAnimations <的位置/ em>的

我的问题是:有没有办法“保存”单元格的子视图位置并从那里开始 deselectedAnimations

0 个答案:

没有答案