UICollectionViewCell Shake [英] UICollectionViewCell Shake

查看:91
本文介绍了UICollectionViewCell Shake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个UICollectionView,并希望让所有单元格像iPhone上跳板的编辑模式一样摇晃。我创建了摇动代码,但不知道如何实现它。我有自定义单元格所以我认为它进入那里但不知道它是如何实现的。谢谢。

I have created a UICollectionView and would like to have all the cells shake like the edit mode of the springboard on the iPhone. I have created my shake code but don't know how to implement it. I have custom cells so I assume it goes in there but don't know how it gets implemented. Thank You.

#define degreesToRadians(x) (M_PI * (x) / 180.0)
#define kAnimationRotateDeg 0.5
#define kAnimationTranslateX 1.0
#define kAnimationTranslateY 1.0

//startJiggling

int count = 1;
CGAffineTransform leftWobble = CGAffineTransformMakeRotation(degreesToRadians( kAnimationRotateDeg * (count%2 ? +1 : -1 ) ));
CGAffineTransform rightWobble = CGAffineTransformMakeRotation(degreesToRadians( kAnimationRotateDeg * (count%2 ? -1 : +1 ) ));
CGAffineTransform moveTransform = CGAffineTransformTranslate(rightWobble, -kAnimationTranslateX, -kAnimationTranslateY);
CGAffineTransform conCatTransform = CGAffineTransformConcat(rightWobble, moveTransform);

    self.transform = leftWobble;  // starting point

    [UIView animateWithDuration:0.1
                          delay:(count * 0.08)
                        options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
                     animations:^{ self.transform = conCatTransform; }
                     completion:nil];


推荐答案

如果你把代码放在一个名为的方法中在您的自定义单元格中 startJiggling ,然后您可以在控制器中调用此方法:

If you put you're code in a method called startJiggling in your custom cell, then you could call this method in your controller:

[self.collectionView.visibleCells makeObjectsPerformSelector:@selector(startJiggling)];

确保所有可见单元格都开始抖动。

That ensures that all visible cells will start jiggling.

然后我还会设置一些标志,指示你的单元格应该在 collectionView:cellForItemAtIndexPath:。如果是,则调用您的方法。

Then I'd also set some flag indicating that your cells should jiggle and test for that in collectionView:cellForItemAtIndexPath:. If YES, then call your method.

这篇关于UICollectionViewCell Shake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆