The logic of CATransform3DRotate

573 Views Asked by At

I try to transform my views similar like on the picture: (top and sideView)

enter image description here

I added each view to the view before (view1 adds view2 which adds view3).

I've got trouble to find the correct way to give view3 the same angle back like view1.

This is what I tried:

CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
    rotationAndPerspectiveTransform.m34 = (1.0/ 500);
    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0 / 180.0 * M_PI , 1, 0, 0);

    [UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{

        self.view1.layer.transform = rotationAndPerspectiveTransform;

    } completion:nil];


    rotationAndPerspectiveTransform = CATransform3DIdentity;
    rotationAndPerspectiveTransform.m34 = (1.0/500);
    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, -45.0 / 180.0 * M_PI , 1, 0, 0);

    [UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{

        self.view2.layer.transform = rotationAndPerspectiveTransform;

    } completion:nil];


    rotationAndPerspectiveTransform = CATransform3DIdentity;
    rotationAndPerspectiveTransform.m34 = (1.0/500);
    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 4.5 / 180.0 * M_PI , 1, 0, 0);


    [UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{

        self.view3.layer.transform = rotationAndPerspectiveTransform;

    } completion:nil];

With this code my View3 turned less than 45 degrees. So my question: how can I turn from from2 to view3 with an angle of 45 degrees?

0

There are 0 best solutions below