美文网首页
table view cell出现时的动画

table view cell出现时的动画

作者: BabyNeedCare | 来源:发表于2018-11-12 15:18 被阅读0次

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    //动画1:

    if (![self.showIndexes containsObject:indexPath]) {

        [self.showIndexes addObject:indexPath];

        CGFloat rotationAngleDegrees = -30;

        CGFloat rotationAngleRadians = rotationAngleDegrees * (M_PI/ 180);

        CGPoint offsetPositioning = CGPointMake(-80, -80);

        CATransform3D transform = CATransform3DIdentity;

        transform = CATransform3DRotate(transform, rotationAngleRadians, 0.0,  0.0, 1.0);

        transform = CATransform3DTranslate(transform, offsetPositioning.x, offsetPositioning.y , 0.0);

        cell.layer.transform = transform;

        cell.alpha = 0.7;

        [UIView animateWithDuration:1 delay:0.0 usingSpringWithDamping:0.6f initialSpringVelocity:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

            cell.layer.transform = CATransform3DIdentity;

            cell.layer.opacity = 1;

        } completion:nil];

    }

    }

//动画2:

    if (![self.showIndexes containsObject:indexPath]) {

        [self.showIndexes addObject:indexPath];

        CATransform3D rotation;

        rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);

        rotation.m34 = 1.0/ -600;

        //2. Define the initial state (Before the animation)

        cell.layer.shadowColor = [[UIColor blackColor]CGColor];

        cell.layer.shadowOffset = CGSizeMake(10, 10);

        cell.alpha = 0;

        cell.layer.transform = rotation;

        cell.layer.anchorPoint = CGPointMake(0, 0.5);

        //3. Define the final state (After the animation) and commit the animation

        [UIView beginAnimations:@"rotation" context:NULL];

        [UIView setAnimationDuration:0.3];

        cell.layer.transform = CATransform3DIdentity;

        cell.alpha = 1;

        cell.layer.shadowOffset = CGSizeMake(0, 0);

        [UIView commitAnimations];

    }

//动画3:

    if (![self.showIndexes containsObject:indexPath]) {

        [self.showIndexes addObject:indexPath];

        cell.layer.transform = CATransform3DTranslate(cell.layer.transform, 300, 0, 0);

        cell.alpha = 0.5;

        [UIView animateWithDuration:0.3 delay:0.0f usingSpringWithDamping:0.8f initialSpringVelocity:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

            cell.layer.transform = CATransform3DIdentity;

            cell.alpha = 1;

        } completion:nil];

    }

相关文章

网友评论

      本文标题:table view cell出现时的动画

      本文链接:https://www.haomeiwen.com/subject/edlcfqtx.html