2012-04-10 133 views
0

我目前正在爲iphone開發一款遊戲,其中許多圖片會圍繞圓圈旋轉。我已經達到了必須編寫代碼來實現這一目標的重要性。我對我必須使用什麼數學運算以及我將如何實現這一點感到困惑。如果可以使用代碼示例來解釋這個過程,這將非常有幫助。如果有人對我的意思感到困惑,我只是試圖以常量速度將UIImageView的中心移動到圓周上。任何幫助表示讚賞。 :)圍繞圓周移動UIImageView?

回答

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 
+0

不太什麼,我一直在尋找,但還是謝謝你:) – Fitzy 2012-04-11 02:23:28