程序员

UICollectionView 和 UITableView 添

2017-04-14  本文已影响533人  _烈日

本文中用到 transform ,如有不会用的,可先看下这里 iOS动画和特效:仿射变换-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];  
   //设置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;  
    }];  
      
}  

原文链接 http://blog.csdn.net/wzios/article/details/52549657
上一篇 下一篇

猜你喜欢

热点阅读