我目前正在为 iphone 开发一款游戏,其中许多图像将围绕圆圈旋转。我已经达到了必须编写代码来实现这一点的地步。我对必须使用哪些数学运算以及如何实现这一点感到困惑。如果可以使用代码示例解释该过程,那将非常有帮助。如果有人对我的意思感到困惑,我只是想以恒定的速度围绕圆周移动 UIImageView 的中心。任何帮助表示赞赏。:)
问问题
310 次
1 回答
0
CGRect rect1;
CGRect rect2;
CGRect rect3;....
在 viewdidload() {
rect1 = imageView1.frame
rect2 = imageView2.frame;
rect3 = imageView3.frame;
[UIImageView beginAnimations:nil context:nil];
[UIImageView setAnimationDelegate:self];
[UIImageView setAnimationBeginsFromCurrentState:YES];
[UIImageView setAnimationDuration:1.5];
[UIImageView setAnimationDidStopSelector:@selector(rotate:)];
imageView1.center = CGPointMake(rect2.origin.x, rect2.origin.y);
imageView1.transform = CGAffineTransformMakeScale(1.2, 1.2);
imageView2.center = CGPointMake(rect3.origin.x, rect3.origin.y);
imageView2.transform = CGAffineTransformMakeScale(2, 2);
[UIImageView commitAnimations];
}
- (void)rotate:(NSString *)animationID
{
[UIImageView beginAnimations:nil context:nil];
[UIImageView setAnimationDelegate:self];
[UIImageView setAnimationBeginsFromCurrentState:YES];
[UIImageView setAnimationDuration:1.5];
[UIImageView setAnimationDidStopSelector:@selector(rotate1:)];
imageView1.center = CGPointMake(rect3.origin.x, rect3.origin.y);
imageView1.transform = CGAffineTransformMakeScale(2, 2);
imageView1.alpha = 1;
imageView2.center = CGPointMake(rect4.origin.x, rect4.origin.y);
imageView2.transform = CGAffineTransformMakeScale(1.2, 1.2);
imageView2.alpha = .5;
.....
[UIImageView commitAnimations];
}
- (void)rotate1:(NSString *)animationID
{
[UIImageView beginAnimations:nil context:nil];
[UIImageView setAnimationDelegate:self];
[UIImageView setAnimationBeginsFromCurrentState:YES];
[UIImageView setAnimationDuration:1.5];
[UIImageView setAnimationDidStopSelector:@selector(rotate2:)];
imageView1.center = CGPointMake(rect4.origin.x, rect4.origin.y);
imageView1.transform = CGAffineTransformMakeScale(1.2, 1.2);
imageView1.alpha = .5;
imageView2.center = CGPointMake(rect5.origin.x, rect5.origin.y);
imageView2.transform = CGAffineTransformMakeScale(1, 1);
imageView2.alpha = .15;
....
[UIImageView commitAnimations];
}
try like this
于 2012-04-10T14:42:29.270 回答