0
votes

Changing the anchor point of a CALayer after a CATransform3dRotate gives weird results. I think the problem is, anchorPoint property is set on the previous state (no transform) of layer not the current state (after transform) of the layer.

enter image description here

Is there a way to change the anchorPoint of a CALayer's current state??

Code for Transform:

     CATransform3D transform = CATransform3DIdentity;

        transform.m34 = -(1.0/800.0);

        videoPlayerView.layer.zPosition = 100;
videoPlayerView.layer.transform = CATransform3DRotate(transform, (30*M_PI)/180, 1.0f, 0.0f, 0.0f);

Code to change the anchor Point

if(videoPlayerView.layer.anchorPoint.x != 0.0)
{
    videoPlayerView.layer.anchorPoint = CGPointMake(0.0, 0.5);

    videoPlayerView.layer.position = CGPointMake(videoPlayerView.layer.frame.origin.x - videoPlayerView.layer.frame.size.width/2,videoPlayerView.layer.position.y);
}

Basically, I have to rotate the Layer like a book flip. I have already done this without using the 30 degree transofrm, but I want it to look more 3D so applied the 30 degree transform along the x axis. So that it looks like the book is placed on a table.

And in order to rotate, setting the anchor point is necessary. If not, please advice otherwise...

1
Can you say what are you trying to achieve? How should it look in the end? - jrturton
basically, I have to rotate the Layer like a book flip. I have already done this, but I want it to look more 3D so applied the 30 degree transform along the x axis. so that it looks like the book is placed on a table. Please check the edited question. - nr5

1 Answers

0
votes

instead of changing anchorPoint use

CATransform3DTranslate(transform, 50.0000f, 0.0000f, 0.0000f);

Translate along X by 50.00 points
Apply 0.40 percent of perspective or you can use the same code you are using right now

rotate the CAlayer using Y .

CATransform3D transform = CATransform3DIdentity;
CATransform3D tmp = CATransform3DIdentity;
transform = CATransform3DRotate(transform, 0.0146f, 0, 1, 0);
transform = CATransform3DTranslate(transform, 50.0000f, 0.0000f, 0.0000f);
tmp = CATransform3DIdentity;
tmp.m34 = 0.0040f;
transform = CATransform3DConcat(transform, tmp);

check the link for more reference.

let me know if it works.