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

发布于 2025-01-01 04:39:33 字数 2808 浏览 0 评论 0原文

我有一个要求,比如点击 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];
}

阿伦..

I have an requirement like on taping on tableView cell it should animate and dropped (jumped)to trash icon.

Am using UIBezierPath to animate the text and jump function but I cant move the label which is inside the tableViewCell.

Any idea and suggestions would be highly appreciated.

Here check the below code so far I have done.

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

Arun..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剧终人散尽 2025-01-08 04:39:34

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

I can suggest to make snapshot of your cell and put it on the current main view in hierarchy (mostly it will self.view) as UIImageView. You delete you cell from table as is, but apply animation for that UIImageView. I've done this trick when tried to make drag-n-drop with UITableViews.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文