2016-03-07 86 views
1

UITableView加載時,我想從右側將其第一個單元格改爲bounce,所以它表示用戶可以向右滑動以刪除cellUITableViewCell上的反彈動畫

我該怎麼做?

我迄今爲止代碼:

注:在下面的代碼我只是讓細胞閃爍,但我真正想要的是細胞反彈。

-(void) tableView:(UITableView *) tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //row number on which you want to animate your view 
    //row number could be either 0 or 1 as you are creating two cells 
    //suppose you want to animate view on cell at 0 index 
    if(indexPath.row == 0) //check for the 0th index cell 
    { 
     // access the view which you want to animate from it's tag 
     NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:1]; 

     UIView *myView = [self.tableView cellForRowAtIndexPath:indexPath]; 
     NSLog(@"row %ld",(long)indexPath.row); 

     // apply animation on the accessed view 
     [UIView animateWithDuration:5 
           delay:2 
          options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut animations:^ 
     { 
      [myView setAlpha:0.0]; 
     } completion:^(BOOL finished) 
     { 
      [myView setAlpha:1.0]; 
     }]; 
    } 
} 

回答

0

如果我正確地理解了這一點,您希望從左到右反彈單元格?

得到一個對單元格引用的內容查看:

NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:1]; 

UIView *contentView = [self.tableView cellForRowAtIndexPath:indexPath].contentView; 

現在有許多方法來「反彈」這個內容查看。一種方法是使用一個動畫塊這樣的:

CGRect original = contentView.frame; 
CGRect bounce_offset = original; 
original.origin.x -= 100.0f; 

我們在這裏做什麼,記得是原來的框架,並決定我們想有多遠我們的反彈在動畫塊到達。然後,我們可以用動畫例如做這樣的事情:

[UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
    contentView.frame = bounce_offset; 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:1.0f delay:0.0f usingSpringWithDamping:0.75f initialSpringVelocity:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{ 
     contentView.frame = original; 
    } completion:^(BOOL finished) { 

    }]; 
}] 

你也可以使用自動翻轉選項,這個「一」的方式來做到這一點,雖然。讓我知道你的想法是什麼!