2009-11-11 38 views
1

我打算創建一個像hang子手一樣的遊戲。我希望每個角色都從頂部出現,就像從頂部飛來。我是否必須進行轉換或僅爲此實現的動畫編碼?UIImageView動畫從頂部飛起來

謝謝。

回答

3

將每個字符放在它自己的UIView實例中,併爲center屬性設置動畫。

//let's say we have a custom UIView subclass that displays a character called 'MYCharacterView' 

MYCharacterView * view = [[MYCharacterView alloc] initWithFrame:CGRectMake(50.0, -10.0, 20.0, 20.0); 
// ... configure the view here, e.g., set the character, etc. ... 
[UIView beginAnimations:nil context:nil]; 
//animate the view from its current position off the top of the screen to 50, 200 
//over 2 seconds 
[view setCenter:CGPointMake(50.0, 200.0)]; 
[UIView setAnimationDuration: 2.0]; 
[UIView commitAnimations]; 

希望幫助!

+0

您需要調用'[UIView setAnimationDuration:2.0];'在更改動畫屬性之前,所以它應該在'setCenter:'之前。 –