UICollectionView UITableView 添加滑动动画


- (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);
        }
    }
}





  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值