0

我想要做的是UIImageView立即翻转它,没有动画,然后我需要它到float它在屏幕上的预期位置。两者都在transformations工作,但不是我想要的方式。

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
resultsEnemy.transform = CGAffineTransformMakeTranslation(0, 0);
[UIView commitAnimations];

resultsEnemy.transform = CGAffineTransformMakeScale(-1, 1);

这是我正在使用的代码。尽管比例代码(我用来翻转UIImageView)不是 0.5 动画的一部分duration,但它遵循这些规则。我该如何避免这种情况?

4

1 回答 1

0

像这样应用两个转换不会产生您期望的结果。您需要做的是将它们组合成一个单一的变换矩阵。以下应该按预期工作。

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];

// Create two separate transforms and concatenate them together.
// Use that new transform matrix to accomplish both transforms at once.
CGAffineTransform translate = CGAffineTransformMakeTranslation(0, 0);
CGAffineTransform scale = CGAffineTransformMakeScale(-1, 1);
resultsEnemy.transform = CGAffineTransformConcat(translate, scale);

[UIView commitAnimations];

编辑:根据您的说明,您似乎想要这样的东西:

CGAffineTransform scale = CGAffineTransformMakeScale(-1, 1);
CGAffineTransform translate = CGAffineTransformMakeTranslation(0, 0);

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
resultsEnemy.transform = scale;
[CATransaction commit];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];

resultsEnemy.transform = CGAffineTransformConcat(translate, scale);

[UIView commitAnimations];
于 2013-02-28T22:02:49.617 回答