How to rotate UIImageView in 3d circular path?

I am new to basic animation. I want to rotate the image left or right, but I want it to rotate along the Z axis so that it looks like a circular rotation. Here is an image for a more detailed explanation.

alt text

I want to rotate the image in the internal view of the image, these are two images.

I tried this code, please someone apply this and fix the code.

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

}

call it with a timer in viewDidLoad or 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];
+3
source share
1 answer

Your question does not match the image. Z goes through the display with negative values ​​closer to you.

2 : - 2D UIKit view.transform - () 3D CALayers view.layer.transform

Z CATransform3DRotate

+1

Source: https://habr.com/ru/post/1732646/


All Articles