2010-02-13 21 views
3

我M個新的核心動畫我想旋轉左或右一個imageview的,但我希望它在z軸的旋轉,以便它可以看起來像一個圓形rotation.Here爲更多的解釋圖像如何以3D循環方式旋轉UIImageView?

alt text http://i45.tinypic.com/e9avx2.png

我想旋轉圖像的內部imageview這些是兩個imageview的。

我已經試過這段代碼,請有人申請並更正代碼。

-(void)Rotate 
{ 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:3.0]; 
CATransform3D t1 = CATransform3DIdentity; 
if(goingCW) 
{ 
    t1 = CATransform3DRotate(t1, radians(90), 0, 1, 0); 
    t1 = CATransform3DTranslate(t1, CUBESIZE/2, 0, 0); 
    t1 = CATransform3DRotate(t1, radians(90), 0, 1, 0); 
    t1 = CATransform3DTranslate(t1, CUBESIZE/2, 0, 0); 
    t1 = CATransform3DRotate(t1, radians(90), 0, 1, 0); 
    t1 = CATransform3DTranslate(t1, CUBESIZE/2, 0, 0); 
    CATransform3D moveTransform = CATransform3DRotate(t1, 0.0, -1.0, 0.0, 0.0); 
    [InnerView.layer setTransform:moveTransform]; 
    NSLog(@"Going Left"); 

} 
else 
{ 
    NSLog(@"Going Right"); 
    t1 = CATransform3DRotate(t1, radians(90), 0, 1, 0); 
    t1 = CATransform3DTranslate(t1, CUBESIZE, 0, 0); 
    CATransform3D moveTransform = CATransform3DRotate(t1, 0.0, 1.0, 0.0, 0.0); 
    [InnerView.layer setTransform:moveTransform]; 

} 
goingCW=!goingCW; 
[UIView commitAnimations]; 

} 

調用此方法,在viewDidLoad中的計時器或在applicationDidFinishLaunching

goingCW = YES; // change this to NO to make it start rotating CCW instead A bool flag in header file. 
    NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(Rotate) userInfo:nil repeats:YES]; 
+6

我相信你的圖片中的滑塊並不使用3D的東西,而是在它的頂部有一個透明圖像的2D滾動視圖。 – kennytm 2010-02-13 07:55:11

回答

1

你的問題不匹配的形象示人。 Z正在通過顯示器,負值接近你。

你有2種變換可供選擇: - 2D上水平的UIKit view.transform - (僞)3D上CALayers view.layer.transform

旋轉變換圍繞Z參數CATransform3DRotate完成