iphone - CGAffineTransformMake 的 UIView 动画不起作用

标签 iphone objective-c

我有一个简单的变换动画,可以将 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/

相关文章:

ios - [UITableView _contentOffsetForScrollingToRowAtIndexPath :atScrollPosition:]

iphone - 应该设置球的哪些物理属性?

iphone - cocoa - 数组不排序?

iphone - 如何在 iPhone 中查看 eps 文件?

iphone - Objective-C : Accessing constants from other classes

iphone - 如何将多个 UIImageView 合并为一个 UIImage

objective-c - 从函数中获取局部变量并在另一个可以动态更改的函数中实现该变量

objective-c - NSSet 实现

iphone - 使用我的应用程序打开文件

ios - iOS 推送通知