【问题标题】:Animating the expansion of a UICollectionViewCell's content upon selection在选择时动画化 UICollectionViewCell 内容的扩展
【发布时间】:2021-11-30 20:08:44
【问题描述】:

如何在选择时为 UICollectionViewCell 的内容展开动画?

目前我在我的 didSelectItemAtIndexPath 上使用过渡动画来为视图设置动画,这不像 AppStore 卡片动画那样流畅。

这是我当前的代码...

AnimateStaticImageViewController *animateImageVC = [[AnimateStaticImageViewController alloc] init];
animateImageVC.modalPresentationStyle = UIModalPresentationFullScreen;
animateImageVC.modelImage = [UIImage imageNamed:text];

[UIView animateWithDuration:0.7 animations:^{
        animateImageVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.3);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.7 animations:^{
            animateImageVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.7 animations:^{
                animateImageVC.view.transform = CGAffineTransformIdentity;
            }];
        }];
    }];
    
[self presentViewController:animateImageVC animated:NO completion:nil];

【问题讨论】:

  • collectionViewLayout上有一个api...让我看看我是否可以绞尽脑汁找到它。我认为它会做你想做的事。
  • AnimatedCollectionViewLayout 吗?我需要写在目标 c 上的东西。谢谢!
  • 不,这是我自己的代码而不是框架。我只是在使用 UICollectionViewLayout。我想我可能对此有疑问。还在寻找:D
  • 给你……我想这就是你要问的……虽然这个问题有点含糊。但听起来您想在为集合视图的布局设置动画的同时为单元格的内容设置动画。 stackoverflow.com/questions/51236002/… 请注意...该问题和答案是用 Swift 编写的,但是(除了轻微的语法更改)一切都应该直接在 Objective-C 中运行。它只是使用香草 UICollectionView。
  • 我刚刚用另一个第三方库here 解决了这个问题。顺便说一句,谢谢@Fogmeister!

标签: ios objective-c uicollectionviewcell uianimation


【解决方案1】:

所以,我在单击图像后立即在我的应用主页 staticImageCollectionView 中尝试了模态过渡动画。 核心动画和转换机制对我不起作用,因为我需要 AppStore 的卡片动画之类的东西。 使用this library 在一些麻烦之后工作!接下来...

  1. 使用following steps 设置库。

  2. 在 didSelectItemAtIndexPath 上调用 animationViewController 的 transitioningDelegate(如果使用 segue-navigation 控制器,则为 prepareForSegue)。

  3. 在完成块中调用它以忽略视图呈现中的闪烁和延迟问题。

AnimatedStaticImageViewController *animateImageVC = [[AnimatedStaticImageViewController alloc] init];
animateImageVC.modalPresentationStyle = UIModalPresentationFullScreen;
animateImageVC.modelImage = [UIImage imageNamed:text];
    
[UIView animateWithDuration:0.2
                     animations:^{
        animateImageVC.transitioningDelegate = self;
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        [self presentViewController:animateImageVC animated:YES completion:nil];
}];
  1. 在设置动画的主要表现形式 imageView 时要小心。

  2. 确保在 fromViewController 和 toViewController 上都声明了委托“RMPZoomTransitionAnimating”和“RMPZoomTransitionDelegate”方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 2012-07-08
    相关资源
    最近更新 更多