此小動畫主要實現(xiàn)的是點擊cell的時候,讓cell縮放一下再恢復(fù)原來的樣子。
我們可以在-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath實現(xiàn) 。
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
RYCollectionCell * cell = (RYCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath];
if (cell) {
[UIView animateWithDuration:0.1 animations:^{
cell.transform = CGAffineTransformMakeScale(0.8, 0.8);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
cell.transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:^(BOOL finished) {
//這里實現(xiàn)點擊cell后要實現(xiàn)的內(nèi)容
}
}];
}];
}
}
(1)animateWithDuration 設(shè)置動畫的時間。
(2)CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)(縮放:設(shè)置縮放比例。
(3)transform我們一般稱為形變屬性,其本質(zhì)是通過矩陣變化改變控件的大小、位置、角度等。iOS提供的三個方法分別:CGAffineTransformMakeRotation(旋轉(zhuǎn))、CGAffineTransformMakeScale(縮放)、CGAffineTransformMakeTranslation(移動)。