2010-02-19 103 views
1

我想旋轉我的對象像搖動骰子。 請建議最簡單的方式在我的iPhone應用程序中實現它。 任何類型的示例代碼或文檔。對象的3D旋轉

回答

2

如果要做到這一點,而不使用OpenGL,你可以使用一個UIImageView和設置一系列動畫圖像。通過創建一系列圖像,您可以創建「滾動骰子」效果。這裏是如何做到這一點的例子:

// create a UIImageView 
UIImageView *rollDiceImageMainTemp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rollDiceAnimationImage1.png"]]; 

// position and size the UIImageView 
rollDiceImageMainTemp.frame = CGRectMake(0, 0, 100, 100); 

// create an array of images that will represent your animation (in this case the array contains 2 images but you will want more) 
NSArray *savingHighScoreAnimationImages = [NSArray arrayWithObjects: 
               [UIImage imageNamed:@"rollDiceAnimationImage1.png"], 
               [UIImage imageNamed:@"rollDiceAnimationImage2.png"], 
               nil]; 

// set the new UIImageView to a property in your view controller 
self.viewController.rollDiceImage = rollDiceImageMainTemp; 

// release the UIImageView that you created with alloc and init to avoid memory leak 
[rollDiceImageMainTemp release]; 

// set the animation images and duration, and repeat count on your UIImageView 
[self.viewController.rollDiceImageMain setAnimationImages:savingHighScoreAnimationImages]; 
[self.viewController.rollDiceImageMain setAnimationDuration:2.0]; 
[self.viewController.rollDiceImageMain.animationRepeatCount:3]; 

// start the animation 
[self.viewController.rollDiceImageMain startAnimating]; 

// show the new UIImageView 
[self.viewController.view addSubview:self.rollDiceImageMain]; 

您可以修改創建和設置,包括大小,位置,數量的圖像,持續時間,重複計數等需要。我用UIImageView的這個特性來創建簡單的動畫效果,它效果很好!

請讓我知道,如果你試試這個,如果它符合你的需求。另外,發佈任何後續問題。

巴特

1

不錯的例子,但你認爲這是可以旋轉/控制與觸摸手勢旋轉?