2010-07-14 70 views
1

我最近下載示例應用程序,GLPaint蘋果。這個應用程序向我展示瞭如何實現繪圖,但現在我想通過畫出的線條爲圖像製作動畫。類似於應用程序「飛行控制」是如何工作的,我希望能夠繪製路徑的圖像,然後有在這個路徑上的圖像動畫。沿着繪製的路徑生成物體?

有什麼想法?

回答

1

CAKeyframeAnimation,這允許您設置的路徑(這是一個CGPathRef)的動畫一起運行。

5

你可以創建你的路徑

CGMutablePathRef thePath = CGPathCreateMutable(); 

,然後在的touchesBegan和touchesMoved添加到您的路徑

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    UITouch *touch = [touches anyObject]; 
    if(touch){ 
    CGPoint tapPoint = [touch locationInView: self.view]; 
    CGPathMoveToPoint(thePath, NULL,tapPoint.x,tapPoint.y);  
    } 
} 
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
    UITouch *touch = [touches anyObject]; 
    if(touch){ 
    CGPoint tapPoint = [touch locationInView: self.view]; 
    CGPathAddLineToPoint(thePath, NULL,tapPoint.x,tapPoint.y); 
    } 
} 

和touchedEnded,因爲約書亞說,創建一個CAKeyframeAnimation並設置其路徑thePath和設置您的動畫(持續時間等)的其他屬性,並將其應用到基於從AtomRiot代碼的對象

0

,我創建了一個簡單的項目,我的BL OG。看到this post,也發佈了一個簡短的視頻顯示結果。

然而,當動畫結束時,圖像會以某種方式重新返回到(0,0),因此可能需要添加額外的代碼動畫完成後重置影像的位置。

另外,發現你不能改變動畫一旦啓動,必須​​等待它結束之前,你可以改變它。

希望這會有所幫助!