Pergunta

I am creating an iPad app and want to update the user with the current size of a view. I used to be doing this by calculating the scale of a CGAffineTransform and multiplying the xScale by the width (of the related view) and the yScale by the height. I'd like to keep doing this, but I'm no longer doing 2d transformations, and I'm sure what equation to use to extract the scale information from CATransform3D.

Can you help?

Foi útil?

Solução

To get the current scale of the layer you just perform a valueForKeyPath: on the layer:

CGFloat currentScale = [[layer valueForKeyPath: @"transform.scale"] floatValue];

Other keys can be found in Apples Core Animation Programming Guide

Outras dicas

I'm not familiar with the API but CATransform3D looks like a regular 4x4 transformation matrix for doing 3D transformations.

Assuming that it represents nothing more than a combination of scale, rotation and translation, the scale factors can be extracted by calculating the magnitudes of either the rows or columns of the upper left 3x3 depending on whether CATransform3D is row or column major respectively.

For example, if it is row-major, the scale in the x-direction is the square root of ( m11 * m11 ) + ( m12 * m12 ) + ( m13 * m13 ). The y and z scales would similarly be the magnitudes of the second and third rows.

From the documentation for CATransform3DMakeTranslation it appears that CATransform3D is indeed row-major.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top