Ios “任意”滑动以删除动画

Ios “任意”滑动以删除动画,ios,xcode,animation,Ios,Xcode,Animation,我正在尝试在刷卡时实现表视图单元格删除,就像在AnyDo应用程序中一样。有什么帮助吗 我的代码: 我正在使用手势识别器 - (UISwipeGestureRecognizer *)swipeRightRecognizer { if (!_swipeRightRecognizer) { _swipeRightRecognizer = [[UISwipeGestureRecognizer alloc] in

我正在尝试在刷卡时实现表视图单元格删除,就像在AnyDo应用程序中一样。有什么帮助吗

我的代码:

我正在使用手势识别器

      - (UISwipeGestureRecognizer *)swipeRightRecognizer 
      { 
        if (!_swipeRightRecognizer)  
           {
            _swipeRightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
            _swipeRightRecognizer.direction = UISwipeGestureRecognizerDirectionRight; 
       }  

        return _swipeRightRecognizer; 
       }
将手势添加到单元格:

       [cell.contentView addGestureRecognizer:self.leftGestureRecognizer];
处理刷卡

       - (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer indexPath: (NSIndexPath *)index
       { 
       if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft)
       { 
        //Table View deletion code.  + Line to be drawn on cell, move that cell to the bottom of the table with animaiton.
       } 
}您可以使用

在您的选择器方法中,您可以处理刷卡:

- (void)yourSelector:(id)sender {
    NSLog(@"Handle swipe");
    UISwipeGestureRecognizer *gRec = sender;
    UITableViewCell *cell = [gRec view];

    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,0,0)];
    [line setImage:[UIImage imageNamed:@"line.png"]];
    [UIView animateWithDuration:0.3 animation:^ (void) {
        [cell addSubview:line];
        [line setFrame:CGRectMake(x,y,320,5];
    } completion:nil];
}
编辑: 我为该行添加了代码,但现在无法尝试。但是,它应该可以使用

在您的选择器方法中,您可以处理刷卡:

- (void)yourSelector:(id)sender {
    NSLog(@"Handle swipe");
    UISwipeGestureRecognizer *gRec = sender;
    UITableViewCell *cell = [gRec view];

    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,0,0)];
    [line setImage:[UIImage imageNamed:@"line.png"]];
    [UIView animateWithDuration:0.3 animation:^ (void) {
        [cell addSubview:line];
        [line setFrame:CGRectMake(x,y,320,5];
    } completion:nil];
}
编辑:
我为该行添加了代码,但现在无法尝试。然而,它应该能工作

科林·埃伯哈特写了一篇关于这个问题的很棒的教程。我还实现了滑动删除功能。

科林·埃伯哈特(Colin Eberhardt)在这方面写了一篇很棒的教程。我还实现了滑动删除功能。

这不是本网站的目的。本网站提供具体的、可回答的问题。不是定制的教程。我问如何实现这个,我不需要教程。任何示例代码都是我需要的。示例代码是一样的。问题是你所说的只是帮助。你还没有表现出你自己解决问题的任何尝试。波顿,看我的编辑。这就是我尝试的。这不是这个网站的目的。本网站提供具体的、可回答的问题。不是定制的教程。我问如何实现这个,我不需要教程。任何示例代码都是我需要的。示例代码是一样的。问题是你所说的只是帮助。你还没有表现出你自己解决问题的任何尝试。波顿,看我的编辑。这就是我尝试的。谢谢,我正在这样做。如何删除一行并将其设置为表格的底部。对于该行,您可以使用UIImageView,它以0,0的宽度和高度开始,并通过[UIView animateWithDuration:animation:completion]设置动画,并在动画块中更改图像视图帧。要制作动画并将单元格放在表格底部,我认为您必须对UITableView进行子类化,以创建自定义动画逻辑。是的,谢谢,ray wenderlich教程非常棒。这正是我想要的。不管怎样,非常感谢。谢谢,我正在这么做。如何删除一行并将其设置为表格的底部。对于该行,您可以使用UIImageView,它以0,0的宽度和高度开始,并通过[UIView animateWithDuration:animation:completion]设置动画,并在动画块中更改图像视图帧。要制作动画并将单元格放在表格底部,我认为您必须对UITableView进行子类化,以创建自定义动画逻辑。是的,谢谢,ray wenderlich教程非常棒。这正是我想要的。不管怎样,谢谢。