Giz
Giz

Reputation: 300

CATransform3D Animation Set X Axis

I have a CATransform3D Animation designed to replace the Push animation currently being used in my app. Currently, it rotates as if the X axis were in the centre of the layer/view. However, I want the X axis to be at the edge of the screen so it flips out of the screen. My current code is: -

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
    rotationAndPerspectiveTransform.m34 = 1.0 / 500;
    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 1.57, 0, 1, 0);
    self.view.layer.transform = rotationAndPerspectiveTransform;
    [UIView commitAnimations];

I'm new to Core Graphics and such, so any pointers, tips, where I'm going wrong will be greatly appreciated!

Upvotes: 0

Views: 858

Answers (1)

murat
murat

Reputation: 4963

You should change the anchorPoint of the layer. Use the following piece of code before beginAnimations:context: method.

CGRect frame = self.view.layer.frame;
self.view.layer.anchorPoint = CGPointMake(1.f, 0.5f);
self.view.layer.frame = frame;

This will change the anchorPoint of the layer without changing the layer position. The rotation animation will be done around the axis that passes from the anchor point.

Upvotes: 1

Related Questions