我想动画重新加载一个集合视图,这样当一个单元被选中时,我得到的动画类似于纸牌游戏中的牌. (成像旧的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]; }
结果: