我已經創建了一個UICollectionView,並希望所有單元格都像iPhone上跳板的編輯模式一樣搖動。我創建了我的搖動代碼,但不知道如何實現它。我有自定義單元格,所以我假設它在那裏,但不知道它如何實現。謝謝。UICollectionViewCell 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];
除了所有偉大的,但最後一個單元格是晃動。當我打印出可見細胞計數並且數組數爲1時,可見細胞計數較低。有任何想法嗎? NSLog(@「visibleCellscount%d」,self.collectionView.visibleCells.count); 的NSLog(@ 「birdscount%d」,self.birds.count); – BDGapps
對不起,沒有想法,沒有更多的代碼... – fguchelaar
但所有細胞都可見?或者你必須滾動最後一個? – fguchelaar