本文中用到 transform ,如有不會(huì)用的,可先看下這里 iOS動(dòng)畫(huà)和特效:仿射變換-CGAffineTransform
1.
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
NSArray *array = collectionView.indexPathsForVisibleItems;
if (array.count == 0) return;
NSIndexPath *firstIndexPath = array[0];
if (firstIndexPath.row < indexPath.row) {
CATransform3D rotation = CATransform3DMakeTranslation(0 ,150 ,0);
cell.alpha = 0;
cell.layer.transform = rotation;
[UIView animateWithDuration:1.0 animations:^{
cell.layer.transform =CATransform3DIdentity;
cell.alpha =1;
cell.layer.shadowOffset =CGSizeMake(0,0);
}];
}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(nonnullUITableViewCell *)cell forRowAtIndexPath:(nonnullNSIndexPath *)indexPath
{
NSArray *array = tableView.indexPathsForVisibleRows;
NSIndexPath *firstIndexPath = array[0];
//設(shè)置anchorPoint
cell.layer.anchorPoint = CGPointMake(0,0.5);
//為了防止cell視圖移動(dòng)涡拘,重新把cell放回原來(lái)的位置
cell.layer.position =CGPointMake(0, cell.layer.position.y);
//設(shè)置cell按照z軸旋轉(zhuǎn)90度梅猿,注意是弧度
if (firstIndexPath.row < indexPath.row) {
cell.layer.transform =CATransform3DMakeRotation(M_PI_2,0,0,1.0);
}else{
cell.layer.transform =CATransform3DMakeRotation(-M_PI_2,0,0,1.0);
}
cell.alpha =0.0;
[UIViewanimateWithDuration:1animations:^{
cell.layer.transform =CATransform3DIdentity;
cell.alpha =1.0;
}];
}