我想在ios中的自定义视图单元格上执行动画

时间:2012-01-30 10:02:04

标签: iphone objective-c uitableview uilabel uibezierpath

我有一个要求,比如在录制tableView单元格时它应该动画并放下(跳转)到垃圾桶图标。

使用UIBezierPath为文本和跳转功能设置动画,但我无法移动tableViewCell内的标签。

任何想法和建议都将受到高度赞赏。

到目前为止,检查以下代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableArray  *views=[[NSMutableArray alloc]init];
    int i=0;
    int j=indexPath.row;
    UIView *anim = nil;
    UIView *vi2;
    for (UIView *theview in destination.superview.subviews) 
    {
//                if (theview.tag != 2)
//                    continue;
        NSLog(@"%@",theview);
        if ([theview isKindOfClass:[UITableView class]]) 
        {
           // NSLog(@"%@",theview);
            UIView *vi= theview;//(UITableView *)[UITableView class];
           // NSLog(@"%@",vi);

           // NSMutableArray  *views=[[NSMutableArray alloc]init];
            for(UIView *vi1 in vi.subviews )
            {
                NSLog(@" the current view....%@",vi1);
                for (int k = 0; k < [arrayList count]; k++)
                {
                    [views insertObject:vi1 atIndex:i++];
                    NSLog(@" ddddd %@",[views objectAtIndex:i-1]);

                }
               }
              //  vi1=(UITableViewCell*)[tableElements objectAtIndex:i];
                anim=(UIView *)[views objectAtIndex:j];
                anim = vi2;   

            for (int k = 0; k < [views count]; k++)
                NSLog (@"Element %d = %@", k, [views objectAtIndex: k]); 



            break;
          }
        }

    if (!anim)
        return;

    UIBezierPath *movePath = [UIBezierPath bezierPath];
    [movePath moveToPoint:anim.center];
    [movePath addQuadCurveToPoint:destination.center
                     controlPoint:CGPointMake(destination.center.x, anim.center.y)];

    CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    moveAnim.path = movePath.CGPath;
    moveAnim.removedOnCompletion = YES;

    CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
    scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
    scaleAnim.removedOnCompletion = YES;

    CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
    opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
    opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
    opacityAnim.removedOnCompletion = YES;

    CAAnimationGroup *animGroup = [CAAnimationGroup animation];
    animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, opacityAnim, nil];
    animGroup.duration = 0.5;
    [anim.layer addAnimation:animGroup forKey:nil];
}

阿伦..

1 个答案:

答案 0 :(得分:1)

我可以建议制作你的单元格的快照,并将它放在层次结构中的当前主视图(通常是self.view)作为UIImageView。您可以按原样从表中删除单元格,但为该UIImageView应用动画。我试图用UITableViews进行拖放时完成了这个技巧。