Applying the same perspective and rotation to all CALayer elements (unlike Coverflow)

I am trying to simulate the appearance of CDs on a shelf. Each CD should be visible at an angle very similar to books when you look at a bookshelf. I use basic animation transformations. The problem is that the result looks like Coverflow, i.e. Elements look different depending on their position on the screen.

Here is a screenshot of what it actually looks like and how I want it to look like this:

what it looks like and what it is supposed to look like

I used CALayers and applied two basic transformations:

1) To rotate:

CATransform3DMakeRotation(DegreesToRadians(60), 0, 1, 0); 

2) To add perspective:

 CATransform3D perspective = CATransform3DIdentity; perspective.m34 = -1.0/400; self.layer.sublayerTransform = perspective; 

How can I apply the same transformation to all layers and are they all alike? Is Core Animation the right tool for the job?

Thanks Mark.

+4
source share
1 answer

Try incorporating the perspective transformation into separate transform elements, rather than into the parent layers of sublayerTransform :

 CATransform3D perspective = CATransform3DIdentity; perspective.m34 = -1.0/400; CATransform3D transform = CATransform3DRotate(perspective, DegreesToRadians(60), 0, 1, 0); element.layer.transform = transform; 
+6
source

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


All Articles