2011-04-15 76 views
0

我有一個圖像旋轉,我想要的是第二個圖像卡在它上面,它像第一個旋轉。請,我該怎麼做?iphone圖像移動像另一個圖像

+0

您可以在旋轉之前將圖像添加到背景圖像上(即,通過重疊像素使圖像在兩個圖像之外)。如果這是可能的,你不需要擔心獨立旋轉兩個。 – Scott 2011-04-15 15:51:11

回答

1

我不在我的電腦,所以我不能測試這個,但我認爲它應該得到你想要的。

// assuming you already have your views 
// viewOne, viewTwo 

[viewOne addSubview:viewTwo]; // add viewTwo to viewOne 

// let's assume that you call this code here one time per second 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.0]; 
[UIView setAnimationCurve:UIViewAnimationCurveLinear]; 

// when this is 1.0, the image will rotate 360 
// ... when it is .5, it should rotate 180, etc... 
float rotationFactor = 0.1f; 

// viewTwo's rotationFactor will be added to view 1's in the transform below 
float rotationFactor2 = 0.1f; 

viewOne.transform = CGAffineTransformMakeRotation(M_PI_2 * rotationFactor); 
viewTwo.transform = CGAffineTransformMakeRotation(M_PI_2 * (rotationFactor + rotationFactor2); 

[UIView commitAnimations];