2013-02-28 80 views
0

我想要做的就是立即翻转这个UIImageView,没有动画,然后我需要它到float它的预期位置在屏幕上。 transformations都在工作,但不是我想要的方式。试图用两个动画动画一个UIImageView动画,只有一个动画有持续时间

[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动画的一部分,但它遵循了这些规则。我如何避免这种情况?

+0

如果你把前变换*动画块? – 2013-02-28 21:57:55

+0

当您应用两个变形时,您只需创建一个(例如使用makeTranslation),然后您必须应用到当前CGAffineTransformRotate(resultsEnemy.transform,...),否则使用第二个变换完全覆盖第一个变形 – Ultrakorne 2013-02-28 21:59:47

回答

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]; 
+0

但这不是我想要做的,我希望比例尺没有持续时间,但我希望翻译持续0.5的持续时间,我不希望他们持续时间为 – mguniverse 2013-02-28 22:43:41

+0

@mguniverse:请参阅我的编辑。如果这不起作用,请在设置缩放转换后删除开始/提交并添加'[CATransaction flush];'。 – 2013-03-07 06:47:11