How to stretch CALayer while maintaining integral origin?

I am trying to stretch the UIView that I have by applying CATransform3DMakeScale to it:

CATransform3DMakeScale(0.9, 1.0 - (0.1 * (path.row - midPath.row)), 1) 

The problem with this is twofold: it leaves me with fractional frames / borders that I can neither twist nor the floor, and it pulls the beginning of my frame so that its origin point is no longer 0.

Is there a way that I can stretch my layer in only one direction? In other words, keep the original position x and y fixed and stretch it toward or away from this origin.

Also, is there documentation anywhere, what are the different mxx variables in CATransform3D for? I looked around and could not find anyone, and trial and error has so far failed.

+4
source share
1 answer

If you want to keep a fixed origin when stretching your CALayer, you can change its anchorPoint property as follows:

 layer.anchorPoint = CGPointMake(0.0f, 0.0f); 

anchorPoint defines the point at which transformations apply to your layer. It is also tied to your position layer, so if you edit anchorPoint , you may need to change the layer again.

Having set the anchor point, you should set your layer with the coordinate of the source origin and stretch it using your transform. However, you will not maintain the integral width and height.

As for the elements of m12 , etc. CATransform3D, this structure is a 4x4 matrix:

 struct CATransform3D { CGFloat m11, m12, m13, m14; CGFloat m21, m22, m23, m24; CGFloat m31, m32, m33, m34; CGFloat m41, m42, m43, m44; }; typedef struct CATransform3D CATransform3D; 

where each value represents one location in the matrix. This matrix is ​​based on 3D OpenGL matrices, such as a model representation matrix. Core Animation provides helper functions for most of the manipulations with this matrix that you will need, but from time to time you will set one of the matrix elements (for example, m34 for the perspective effect).

I have never been good at math, but you can find any of the comments that people put together for math for OpenGL display mockups and apply it here.

+2
source

Source: https://habr.com/ru/post/1344134/


All Articles