选择时更改UICollectionViewCell

时间:2014-04-17 07:10:56

标签: ios uicollectionviewcell

我尝试在选中时为单元格设置动画,但我的代码不会使图像隐藏起来。

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
PageCell *selectedCell = [self.collectionView cellForItemAtIndexPath:indexPath];

selectedCell.pageImg.hidden = YES;
[selectedCell.pageSnipper startAnimating];

[[PageStore sharedStore] likeAndUpdatePageAtIndex:indexPath.item];

[collectionView reloadItemsAtIndexPaths:@[indexPath]];

selectedCell.pageImg.hidden = NO;
[selectedCell.pageSnipper stopAnimating];

[self updateLikeCountWithNumberOfLikes:1];
}

1 个答案:

答案 0 :(得分:0)

遗憾的是,

hidden不是动画属性。

动画隐藏视图的最佳方法是使用以下内容为视图的alpha设置动画:

[UIView animateWithDuration:0.25 animations:^{
    selectedCell.pageImg.alpha = 0.0f;
} completion:^(BOOL finished) {
    [[PageStore sharedStore] likeAndUpdatePageAtIndex:indexPath.item];
    [collectionView reloadItemsAtIndexPaths:@[indexPath]];
    [UIView animateWithDuration:0.25 animations:^{
        selectedCell.pageImg.alpha = 1.0f;
    }];
}];

这将使图像不可见,然后在更新完成后再次显示。