我创建了一个 UICollectionView 并希望所有单元格都像 iPhone 上跳板的编辑模式一样摇动。我已经创建了我的 shake 代码,但不知道如何实现它。我有自定义单元格,所以我假设它在那里,但不知道它是如何实现的。谢谢。
#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
的方法中,那么您可以在 Controller 中调用此方法:
[self.collectionView.visibleCells makeObjectsPerformSelector:@selector(startJiggling)];
这确保所有可见的单元格都将开始抖动。
然后我还会设置一些标志,指示您的单元格应该抖动并在 collectionView:cellForItemAtIndexPath:
中测试它。如果是,则调用您的方法。
关于iphone - UICollectionViewCell 抖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14025600/