tableview cell推出动画

//tableview.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"Order";
    JYOrderListTableViewCell *cell = (JYOrderListTableViewCell *)[tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[JYOrderListTableViewCell alloc]init];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    //设置时间差,让view不同时间推出
    static CGFloat initialDelay = 0.2f;
    static CGFloat stutter = 0.06f;
    
    JYOrderListTableViewCell *orderCell = (JYOrderListTableViewCell *)cell;
    [orderCell startAnimationWithDelay:initialDelay + ((indexPath.row) * stutter)];
}

//cell.h

- (void)startAnimationWithDelay:(CGFloat)delayTime;

//cell.m

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.viewCell = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40)];
        
        UIImageView *imageview = [[UIImageView alloc]init];
        imageview.image = [UIImage imageNamed:@"5th-row"];
        imageview.frame = CGRectMake(10, 5, [UIScreen mainScreen].bounds.size.width - 20, 40);
        [self.viewCell addSubview:imageview];
        [self addSubview:self.viewCell];
    }
    return self;
}

- (void)startAnimationWithDelay:(CGFloat)delayTime
{
    //设置平移出视图
    _viewCell.transform =  CGAffineTransformMakeTranslation([UIScreen mainScreen].bounds.size.width, 0);
    [UIView animateWithDuration:1. delay:delayTime usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
        //动画平移回来
        _viewCell.transform = CGAffineTransformIdentity;
    } completion:NULL];
}

 

转载于:https://my.oschina.net/u/2556411/blog/688796

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值