2013-10-06 21 views
0

我有一個UIImageView,我試圖做一個UIImages動畫的創建通過翻轉其他UIImages。這裏是我的代碼:UIImageView將不會動畫與UIImages的CGImage

turtle = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width-200, 
                    self.view.frame.size.height - sand.frame.size.height - turtle.frame.size.height - 10 - heightOfKeyboard, 
                    100,100)]; 
[flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle1.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]]; 
[flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle2.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]]; 
[flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle3.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]]; 
[flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle2.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]]; 
[self.view addSubview: turtle]; 

問題是,當我試圖使它從翻轉圖像陣列動畫,它顯示了原件,沒有被翻動的人(也就是,當我這樣做):

turtle.animationImages = flippedTurtleArray; 
turtle.animationDuration = 0.8f; 
turtle.animationRepeatCount = 0; 
[turtle startAnimating]; 

顯示原始非翻轉圖像。現在

,如果我這樣做不過:

turtle.image = [flippedTurtleArray objectAtIndex:1]; 

被翻動的圖像顯示。我想也許你不能用CGImage做動畫,但是找不到其他人有同樣的問題。有任何想法嗎?

感謝,

山姆

回答

0

我會看着CGLayer屬性,特別是變換層的屬性。

Transform屬性具有動畫效果,可以將任意變換應用於原始圖像,而無需管理中間翻轉的Turtle陣列。

應用於圖層內容的變換。動畫。

@property CATransform3D變換 討論 此屬性設置爲標識默認變換。應用於圖層的任何轉換都是相對於圖層的定位點而言的。

供貨情況 適用於iOS 2.0及更高版本。 相關示例代碼 oalTouch 宣佈 CALayer.h

如果您有其他原因想要的數組,那麼你可能要被翻動的圖像渲染成一個單獨的圖像,並將其傳遞到您的陣列。

同樣,如果你可以使用iOS 7作爲目標,看看一個SpriteKit,它可能會使整個任務更簡單。

+0

嗨 - 我將如何將翻轉的圖像渲染成單獨的圖像?我看不到如何做到這一點? –

+0

阿好 - 知道了 - 我改變方法,只是發現如何翻轉實際圖像數據而不是國旗。不管怎麼說,還是要謝謝你。 –