首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionViewCell翻转和按需增长

UICollectionViewCell翻转和按需增长
EN

Stack Overflow用户
提问于 2012-12-07 22:25:44
回答 2查看 7.3K关注 0票数 10

我如何实现UICollectionViewCell翻转和增长的动画,以显示点击模式视图?

EN

回答 2

Stack Overflow用户

发布于 2013-07-09 10:01:33

这是我在另一个项目中使用的,它工作得很好:

代码语言:javascript
复制
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    if (cell.selected) {
        [collectionView deselectItemAtIndexPath:indexPath animated:YES];
        [UIView transitionWithView:cell
                          duration:0.2
                           options:UIViewAnimationOptionTransitionFlipFromLeft
                        animations:^{
                            [cell setFrame:self.selectedCellDefaultFrame];
                            cell.transform = self.selectedCellDefaultTransform;
                        }
                        completion:^(BOOL finished) {
                            self.selectedCellDefaultFrame = CGRectZero;
                            [collectionView reloadItemsAtIndexPaths:@[indexPath]];
                        }];
        return NO;
    }
    else {
        return YES;
    }
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    [cell.superview bringSubviewToFront:cell];
    self.selectedCellDefaultFrame = cell.frame;
    self.selectedCellDefaultTransform = cell.transform;
    [UIView transitionWithView:cell
                      duration:0.2
                       options:UIViewAnimationOptionTransitionFlipFromRight
                    animations:^{
                        [cell setFrame:collectionView.bounds];
                        cell.transform = CGAffineTransformMakeRotation(0.0);
                    }
                    completion:^(BOOL finished) {}];
}

这里有不同的东西:

  • bringSubviewToFront:消息调用用于防止单元格在其他单元格后面运动
  • 我们使用控制器中声明的两个属性:selectedCellDefaultFrameselectedCellDefaultTransform来保存单元格的默认状态并在取消选择deselecting
  • When时重新初始化它,我们调用UICollectionViewreloadItemsAtIndexPaths:方法以确保位置的重置完全完成

如果你在这方面有任何问题,请告诉我。

祝好运,

票数 7
EN

Stack Overflow用户

发布于 2012-12-17 04:34:40

我还没有尝试过grow动画,但我想我可以在UICollectionViewCell flip动画中提供帮助。

尝试:

代码语言:javascript
复制
UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];

[UIView animateWithDuration:1.0
                      delay:0
                    options:(UIViewAnimationOptionAllowUserInteraction)
                 animations:^
                {
                     NSLog(@"starting animation");

                    [UIView transitionFromView:cell.contentView
                                        toView:newView
                                      duration:.5
                                       options:UIViewAnimationOptionTransitionFlipFromRight
                                    completion:nil];
                }
                 completion:^(BOOL finished)
                {
                     NSLog(@"animation end");
                }
 ];

希望这能有所帮助!

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13765006

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档