我试图像晃动骰子一样旋转我的物体。 请建议在我的iphone应用程序中实现它的最简单方法。 任何类型的示例代码或文档。
答案 0 :(得分:3)
答案 1 :(得分: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的这个功能来创建简单的动画效果,效果很好!
如果您尝试这个并且它是否适合您的需要,请告诉我。另外,发布任何后续问题。
巴特
答案 2 :(得分:1)
很好你的例子,但你认为用触摸手势旋转/控制旋转是否可能?