2011-09-25 94 views
4

我有一个简单的转换动画,将UITableViewCell 70像素向左移动。在if部分,动画效果很好,并且我得到了平滑过渡。但是,当再次调用函数以将单元放回其原始位置(即else部分)时,我不会获得动画。它只是恢复正常,但没有动画。我怎样才能解决这个问题?UIView动画CGAffineTransformMake不工作

if([[slideArray objectAtIndex:indexPath.row] intValue]==0) 
    { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.4]; 
     selectedCell.transform=CGAffineTransformMakeTranslation(-70, 0); 
     [UIView commitAnimations]; 
     [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:1]]; 

    } 

    else 
    { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.4]; 
     selectedCell.transform=CGAffineTransformMakeTranslation(0, 0); 
     [UIView commitAnimations]; 
     [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:0]]; 
    } 
+0

不确定它会帮助你解决问题,但指定第二个转换的正常方法是CGAffineTransformIdentity。 – morningstar

+0

这并没有解决我的问题 – Snowman

回答

9

尝试在其他条件下的动画,这将正常工作,如果你有alreadyb执行,如果条件....

[UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.4]; 
    selectedCell.transform=CGAffineTransformMakeTranslation(70, 0); 
    [UIView commitAnimations]; 
    [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:0]]; 

如果工作不适合你上面的代码不是尝试以下

翻译
[UIView animateWithDuration:0.5 
        delay:0 
       options:UIViewAnimationOptionBeginFromCurrentState 
      animations:(void (^)(void)) ^{ 
       myImageView.transform=CGAffineTransformMakeTranslation(-70, 0); 
      } 
      completion:^(BOOL finished){ 
       myImageView.transform=CGAffineTransformIdentity; 
      }]; 
    [slideArray replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithInt:0]]; 

让我知道,如果有任何问题.. 问候。

+0

动画为我修复后,将变换设置回'CGAffineTransformIdentity'。谢谢! – Paul