简体   繁体   中英

Get the 'Z value' of a point

I'm implementing an app' in which i use some 'CALayers' to create some forms. For example :

testLayer = [CALayer layer];
testLayer.frame = layerRect;
testLayer.position = self.view.center;

CGFloat degrees = 90.0;
CGFloat radians = DegreesToRadians(degrees);
CATransform3D rotation = CATransform3DMakeRotation(radians, 0.0, 1.0, 0.0);
CATransform3D translation = CATransform3DMakeTranslation(Layer_Size/2, 0.0, Layer_Size/-2);
CATransform3D position = CATransform3DConcat(rotation, translation);
testLayer.transform = position;

This layer is add in a :

transformLayer = [CATransformLayer layer];
[transformLayer addSublayer:testLayer];
transformLayer.anchorPointZ = Layer_Size/-2;

But i want to get the Z value of a point which is on the testLayer and is named testLayerPoint (of type 'UIView', with size 1x1), because when i want to project the coordinates into the plan of the principal view like this :

CGRect rectTest = [testLayerPoint.layer convertRect:[[testLayerPoint.layer presentationLayer] frame] toLayer:self.view.layer];

The code :

NSLog(@"%f", rectTest.x);

gives not the correct coordinates… So i want to get the Z value directly.

Thanks !

If by Z value you're referring to the zPosition, that can be found by calling the zPosition property on any CALayer . It defaults to 0.

From the docs:

Changing the value of this property changes the the front-to-back ordering of layers onscreen. This can affect the visibility of layers whose frame rectangles overlap.

The value of this property is measured in points.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM