代码之家  ›  专栏  ›  技术社区  ›  Rahul Vyas

如何以三维圆形方式旋转UIImageView?

  •  3
  • Rahul Vyas  · 技术社区  · 15 年前

    alt text

    我想旋转图像,内部图像,这是两个图像。

    我已经试过这个代码,请有人应用这个并更正代码。

    -(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];
    
    }
    

    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];
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Cocoanetics    14 年前

    你的问题与图片显示的不匹配。Z在屏幕上的负值离你更近。

    您有两种可用的转换: -UIKit view.transform级别的2D

    使用CATransform3DRotate围绕Z进行旋转变换