Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CATransform3D rotate causes half of image to disappear

I'm using the following code to rotate an image, but half the image (down the y-axis) that has been rotated "out of" the page, disappears. How to fix? heading is in radians.

    CALayer *layer = myUIImageView.layer;
    CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
    rotationAndPerspectiveTransform.m34 = 1.0 / 500;
    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, heading, 0.0f, 1.0f, 0.0f);
    layer.transform = rotationAndPerspectiveTransform;
like image 490
iPadDeveloper2011 Avatar asked Feb 19 '11 06:02

iPadDeveloper2011


2 Answers

  layer.anchorPoint = CGPointMake(0.0, 0.0);
like image 32
Liam Donaghy Avatar answered Nov 03 '22 06:11

Liam Donaghy


The solution to this was to set the zPosition property of all my layers appropriately. Thanks is due to @Brad Larson, who suggested this solution in a comment here. It seems that, when you start using CATransform3D, the normal zindex view hierarchy established by addsubview is thrown out the window.

like image 76
iPadDeveloper2011 Avatar answered Nov 03 '22 05:11

iPadDeveloper2011