ios – UICollectionView上的自定义动画重新加载数据

前端之家收集整理的这篇文章主要介绍了ios – UICollectionView上的自定义动画重新加载数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想动画重新加载一个集合视图,这样当一个单元被选中时,我得到的动画类似于纸牌游戏中的牌. (成像旧的MS纸牌)

我一直在寻找“自定义UICollectionView重载动画”,并看到了诸如此类的解决方

[self.collectionView performBatchUpdates:^{
[self.collectionView reloadItemsAtIndexPaths:myindexPaths]
} completion:nil];

并且想到了这一点

CATransition *transition = [CATransition animation];
    transition.duration = 1;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaSEOut];
    transition.type = kCATransitionMoveIn;
    [self.collectionView.layer addAnimation:transition forKey:nil];
    [self.collectionView reloadData];
    return;

但它没有达到我想要的效果.
有什么想法可以做到吗?

解决方法

你可以像建议 here那样做一些技巧
+ (CATransition *)swipeTransitionToLeftSide:(BOOL)leftSide
{
    CATransition* transition = [CATransition animation];
    transition.startProgress = 0;
    transition.endProgress = 1.0;
    transition.type = kCATransitionPush;

    transition.subtype = leftSide ? kCATransitionFromRight : kCATransitionFromLeft;
    transition.duration = AnimationDuration;
    return transition;
}

并将其添加到您的collectionView

UISwipeGestureRecognizer *swipeGestureL = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeToLeftCollectionView:)];
swipeGestureL.direction = UISwipeGestureRecognizerDirectionLeft;
[self.collectionView addGestureRecognizer:swipeGestureL];

- (void)didSwipeToLeftCollectionView:(UISwipeGestureRecognizer *)swipeGesture
{
    [self.collectionView.layer addAnimation:[Animation swipeTransitionToLeftSide:YES] forKey:nil];
    [self.collectionView reloadData];
}

结果:

猜你在找的iOS相关文章