3D cube problem! Part 1

I created a 3D cube in iphone using CALayer's . Now I wanted to rotate this cube ( CALayer ) 90˚ when the user double-clicks on it.

I managed to rotate this cube ( CALayer ) up to 90˚ once, but when I double-click the cube ( CALayer ), it does not rotate.

Here is the code I used to rotate the cube ( CALayer )

 CATransform3D x = CATransform3DRotate(currentLayer.sublayerTransform, M_PI / 2, 0, 0, 1); currentLayer.transform = x; 

Can anyone help with this. What am I doing wrong.


PS. For people who are wondering how I got a degree sign, here's the trick

Option + K

+3
source share
1 answer

because you don’t change the rotation angle .... to understand this, you can say that you pass M_PI / 2 each time to this method .... so CATransform3DRotate do not rotate it to the next 90˚ rather it rotates the layer to the specified angle, in this case its 90 ... so you are not getting any chage because it is already 90˚ ..... therefore, to get the correct result, do it

 static float angle = M_PI / 2;//dont make it static rather make it a global variable angle += M_PI / 2; CATransform3D x = CATransform3DRotate(currentLayer.sublayerTransform,angle, 0, 0, 1); currentLayer.transform = x; 
+2
source

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


All Articles