简体   繁体   English

如何使用UICollectionView实现此单元格动画

[英]How to implement this cell animation with UICollectionView

I'm trying to make this animation 我正在尝试制作这个动画

For the list, I think I can use UICollectionView , but the animation part seem to be tricky. 对于列表,我想我可以使用UICollectionView ,但动画部分似乎很棘手。

Any idea on this? 有什么想法吗?

If you mean the springing animation part, that is not very tricky - Apple has a demo of exactly that behavior in same code for UIDynamics (iOS7+ only). 如果你的意思是弹性动画部分,那不是很棘手 - 苹果公司在UIDynamics相同代码(仅限iOS7 +)中有一个完全相同的演示。

There is another example here that looks very close to what you are after: 这里有另一个例子,看起来非常接近你所追求的:

http://www.objc.io/issue-5/collection-views-and-uidynamics.html http://www.objc.io/issue-5/collection-views-and-uidynamics.html

Look in the middle for an animated example. 在中间查看动画示例。 It even uses collection views. 它甚至使用集合视图。

As @Kendall said, you really need to try UIDynamics . 正如@Kendall所说,你真的需要尝试UIDynamics

For a quick workaround, I just tried below code. 为了快速解决方法,我只是尝试下面的代码。 It works somewhat good and related to your code. 它的工作方式有点好,与您的代码有关。 I don't know about performance. 我不知道表现。 So It may create a performance lack in your project. 因此,它可能会导致项目缺乏性能。

It is just an idea. 这只是一个想法。 If it is not working for you, leave it as it is. 如果它不适合您,请保持原样。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCollectionViewCell" forIndexPath:indexPath];

    [UIView animateWithDuration:0.2 animations:^{
        cell.transform = CGAffineTransformMakeTranslation(0.0, -50);
    }];
    [self delayBy:0.5 code:^{ // call block of code after time interval
        [UIView animateWithDuration:0.3 animations:^{
            cell.transform = CGAffineTransformIdentity;
        }];
    }];
    return cell;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM