1

我需要为每个单元格设置动画,当用户转向从 screen1 显示 tableview 到 screen2 时。是否可以这样做,请帮助我。

提前致谢

我试过这个:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell Identifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell.png"]];
    }

    CATransition *transition = [CATransition animation];
    transition.duration = 1;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = @"cube";
    transition.subtype = kCATransitionFromBottom;
    transition.delegate = self;
    [cell.layer addAnimation:transition forKey:nil];

    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.text = [shopList objectAtIndex:indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f];
    return cell;
}
4

3 回答 3

1

像这样试试

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell Identifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell.png"]];
    }

    [UIView beginAnimations:@"RESIZE_BG" context:NULL];
    [UIView setAnimationDuration:0.5];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.text = [shopList objectAtIndex:indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f];
    [UIView commitAnimations];

    return cell;
}
于 2013-05-22T12:20:45.770 回答
1

在 willDisplayCell 中尝试动画:表委托方法

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

if (!isAnimate)
{
    CABasicAnimation *rotationAnimation;

    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"position"];

    rotationAnimation.fromValue=[NSValue valueWithCGPoint:CGPointMake([cell center].x+320, [cell center].y)];
    rotationAnimation.toValue=[NSValue valueWithCGPoint:CGPointMake([cell center].x, [cell center].y)];

    rotationAnimation.duration = 1.0+i;
    rotationAnimation.speed = 3.0;

    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 1.0;
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

    [cell.layer addAnimation:rotationAnimation forKey:@"position"];

    i=i+0.5;
}
}
于 2013-08-08T10:26:29.477 回答
0

尝试这个

[tblView insertRowsAtIndexPaths:tempArray withRowAnimation:UITableViewRowAnimationTop];
于 2013-08-08T10:53:45.797 回答