- (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;//3D旋转
rotation =CATransform3DMakeTranslation(0 ,150 ,20);
// rotation = CATransform3DRotate(rotation,M_PI, 0, 0.5, 0.0);
// CATransform3DMakeRotation(M_PI, 0, 0.5, 0.0);
//逆时针旋转
rotation =CATransform3DScale(rotation,0.9,0.9,1);
rotation.m34 =1.0/ -600;
cell.layer.shadowColor = [[UIColorblackColor]CGColor];
cell.layer.shadowOffset =CGSizeMake(10,10);
cell.alpha =0;
cell.layer.transform = rotation;
[UIViewanimateWithDuration:1.0animations:^{
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];
//设置anchorPoint
cell.layer.anchorPoint =CGPointMake(0,0.5);
//为了防止cell视图移动,重新把cell放回原来的位置
cell.layer.position =CGPointMake(0, cell.layer.position.y);
//设置cell按照z轴旋转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;
}];
}
cell子控件增加动画
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat viewHeight = scrollView.height + scrollView.contentInset.top;
for (YYWebImageExampleCell *cellin [self.tableViewvisibleCells]) {
CGFloat y = cell.centerY - scrollView.contentOffset.y;
CGFloat p = y - viewHeight /2;
CGFloat scale =cos(p / viewHeight * 0.8) *0.95;
if (kiOS8Later) {
[UIViewanimateWithDuration:0.15delay:0options:UIViewAnimationOptionCurveEaseInOut |UIViewAnimationOptionAllowUserInteraction |UIViewAnimationOptionBeginFromCurrentStateanimations:^{
cell.webImageView.transform =CGAffineTransformMakeScale(scale, scale);
} completion:NULL];
} else {
cell.webImageView.transform =CGAffineTransformMakeScale(scale, scale);
}
}
}