2013-02-22 116 views
1

Any do swipe to delete animation「AnyDo」刷卡刪除動畫

我想實現刷卡上表視圖刪除單元格象是在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. 
     } 

}

+0

這不是這個網站的用途。此網站用於*特定的,可回答的問題。不是定製的教程。 – borrrden 2013-02-22 10:48:05

+0

我問如何實現這一點,我不需要一個教程。任何示例代碼都是我需要的。 – satheeshwaran 2013-02-22 10:52:33

+0

示例代碼是相同的東西。問題是你所說的是「幫助」。你還沒有顯示出你自己解決問題的任何嘗試。 – borrrden 2013-02-22 10:54:30

回答

3

您可以使用UISwipeGestureRecognizer

UISwipeGestureRecognizer *gRec = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(yourSelector:)]; 
[gRec setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)]; 

[yourCell addGestureRecognizer:gRec]; 

在yourSelector方法可以處理輕掃:

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

編輯: 我添加了一行代碼,但我不能現在就試試吧。然而,它應該工作

+0

謝謝,我正在這樣做。如何在時尚動作中打出一排,並將其放在桌子的底部。 – satheeshwaran 2013-02-22 10:54:13

+0

對於「行」,您可以使用UIImageView,以寬度和高度爲0,0開始,並通過[UIView animateWithDuration:animation:completion]對動畫進行動畫處理,並在動畫塊中更改圖像視圖框。要動畫並將單元格放在表格的底部,我認爲您必須繼承UITableView以創建自定義動畫邏輯。 – 2013-02-22 10:58:17

+0

看到我的編輯,我添加了線圖的代碼 – 2013-02-22 11:03:32