//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];
}