我有一个简单的变换动画,可以将 UITableViewCell 向左移动 70 像素。在 if
部分,动画效果很好,我得到了一个平滑的过渡。但是,当再次调用该函数以将单元格放回其原始位置时,即 else
部分,我看不到任何动画。它只是恢复正常但没有动画。我该如何解决这个问题?
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]];
}
最佳答案
在 else 条件下尝试以下动画,如果您已经执行 if 条件的翻译,这将正常工作....
[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]];
让我知道如果有任何问题.. 问候。
关于iphone - CGAffineTransformMake 的 UIView 动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7548035/