UITableViewCell上的反弹动画

问题描述:

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

如果我正确地理解了这一点,您希望从左到右反弹单元格?

得到一个对单元格引用的内容查看:

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) { 

    }]; 
}] 

你也可以使用自动翻转选项,这个“一”的方式来做到这一点,虽然。让我知道你的想法是什么!